Sha256: c6c44fa3f3bb6b3dc1d0e9f14ec6b9023a2aacb91d9cbdd5d237df43ee3a86ef

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require_relative "playbook_helpers"

module AnsibleUtils
  class DependencyManager
    include PlaybookHelpers

    attr_reader :playbook_path, :options

    def initialize playbook_path, options = {}
      @playbook_path = playbook_path
      @options = options
    end

    def symlink_roles
      paths.each{|path| execute_in_path(:symlink, path) }
    end

    def copy_roles
      paths.each{|path| execute_in_path(:copy, path) }
    end

    private

    def execute_in_path action, path
      populate_ansible_path = File.join(generic_roles_folder, path) if generic_roles_folder
      project_path = File.join(project_folder, path)
      file_utils_method = action == :copy ? :copy_entry : :ln_s

      if !File.directory?(populate_ansible_path)
        puts "- Ignoring role '#{path}' because it does not exist in populate-ansible"
      else
        dirname = File.dirname(project_path)
        if Dir.exists?(project_path)
          if options.force
            puts "+ Overwritting role '#{path}'"
            delete_if_exists(project_path)
          else
            puts "- Skipping existing role '#{path}' (use --force option to overwrite it)"
            return
          end
        end
        puts "+ Adding role '#{path}'"
        FileUtils.mkdir_p(dirname)
        FileUtils.send(file_utils_method, populate_ansible_path, project_path)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ansible-utils-0.1.0 lib/ansible_utils/dependency_manager.rb