Module: AnsibleUtils::PlaybookHelpers

Included in:
DependencyManager
Defined in:
lib/ansible_utils/playbook_helpers.rb

Instance Method Summary collapse

Instance Method Details

#config_file_pathObject



4
5
6
# File 'lib/ansible_utils/playbook_helpers.rb', line 4

def config_file_path
  @config_file_path ||= File.join(ENV.fetch('HOME'), '.config', 'ansible-utils', 'config.yml')
end

#delete_if_exists(path) ⇒ Object



8
9
10
# File 'lib/ansible_utils/playbook_helpers.rb', line 8

def delete_if_exists path
  FileUtils.remove_entry(path, true)
end

#generic_roles_folderObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ansible_utils/playbook_helpers.rb', line 30

def generic_roles_folder
  begin
    if File.file?(config_file_path)
      return YAML.load(File.read(config_file_path))['generic_roles_path']
    else
      raise "Missing config file at #{config_file_path}. Run `ansible-utils config` for proper setup"
    end
  rescue Psych::SyntaxError
    raise "Error reading config file at #{config_file_path}"
  end
end

#pathsObject



12
13
14
15
16
17
18
19
20
# File 'lib/ansible_utils/playbook_helpers.rb', line 12

def paths
  @paths ||= roles.map do |role|
    if role.is_a?(Hash)
      role['role']
    else
      role
    end
  end
end

#playbookObject



42
43
44
# File 'lib/ansible_utils/playbook_helpers.rb', line 42

def playbook
  @playbook ||= YAML.load_file(playbook_path).first
end

#project_folderObject



26
27
28
# File 'lib/ansible_utils/playbook_helpers.rb', line 26

def project_folder
  @project_folder ||= Dir.pwd
end

#rolesObject



22
23
24
# File 'lib/ansible_utils/playbook_helpers.rb', line 22

def roles
  playbook['roles']
end