Perform filepath checking in python
Checking for all of the paths in ansible leads to a TON of skipped lines in the ansible log. That's not good for anybody, and we're already processing the paths in python - let's do a quick filter to check for which ones exist before returning them. Change-Id: Iddf3c56c802598329a18c374cf667a6f165f78ca
This commit is contained in:
parent
6260b48b9e
commit
c25e5aa543
@ -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 *
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user