diff --git a/library/puppet_get_hiera_file_list b/library/puppet_get_hiera_file_list index a37019f..a4fbefb 100644 --- a/library/puppet_get_hiera_file_list +++ b/library/puppet_get_hiera_file_list @@ -30,6 +30,10 @@ options: description: - The groups the host is in required: true + location: + description: + - Base hiera location in which to look for files + required: true requirements: [ ] author: Monty Taylor ''' @@ -40,13 +44,25 @@ def main(): argument_spec=dict( fqdn=dict(required=True), groups=dict(required=True), + location=dict(required=True), ), ) p = module.params - module.exit_json(paths_dict = {'paths': [ + paths = [ 'common.yaml', - 'fqdn/%s.yaml' % p['fqdn'] ] + ['group/%s.yaml' % f for f in p['groups'] ]}) + 'fqdn/%s.yaml' % p['fqdn'] ] + paths = ['group/%s.yaml' % f for f in p['groups'] ] + paths.append('common.yaml') + paths.append('fqdn/%s.yaml' % p['fqdn']) + + good_paths = [] + for path in paths: + full_path = os.path.join(p['location'], path) + if os.path.exists(full_path): + good_paths.append(full_path) + + module_exit_json(paths=good_paths) # import module snippets from ansible.module_utils.basic import * diff --git a/tasks/main.yml b/tasks/main.yml index 0134949..b862a0b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,25 +28,16 @@ puppet_get_hiera_file_list: fqdn: "{{ ansible_fqdn }}" groups: "{{ hostvars[inventory_hostname].group_names }}" + location: "{{ hieradata }}/{{ hieraenvironment }}" delegate_to: localhost register: hiera_file_paths - - name: find which files exist - stat: - path: "{{ hieradata }}/{{ hieraenvironment }}/{{ item }}" - register: st - with_items: hiera_file_paths.paths_dict.paths - delegate_to: localhost - - name: copy hiera files - when: item.1.stat.exists copy: - src: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}" - dest: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}" + src: "{{ item }}" + dest: "{{ item }}" mode: 0600 - with_together: - - hiera_file_paths.paths_dict.paths - - st.results + with_items: hiera_file_paths.paths - name: ensure hieradata manifest link is present file: