Copy in matching hiera files
Find any files that match common, $fqdn and $group in the hiera structure and copy them to the target host's hiera structure so that the puppet apply command can operate. Change-Id: I833858e86b9e8fe0750642476f118ca7d0358380
This commit is contained in:
parent
fef11fbbdf
commit
c424d8b555
54
library/puppet_get_hiera_file_list
Normal file
54
library/puppet_get_hiera_file_list
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# This module is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This software is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: puppet_get_hiera_file_list
|
||||
short_description: Create a list of hiera file paths
|
||||
description:
|
||||
- Create a list of hiera file paths
|
||||
options:
|
||||
fqdn:
|
||||
description:
|
||||
- The ansible fqdn
|
||||
required: true
|
||||
groups:
|
||||
description:
|
||||
- The groups the host is in
|
||||
required: true
|
||||
requirements: [ ]
|
||||
author: Monty Taylor
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
fqdn=dict(required=True),
|
||||
groups=dict(required=True),
|
||||
),
|
||||
)
|
||||
p = module.params
|
||||
|
||||
module.exit_json(paths_dict = {'paths': [
|
||||
'common.yaml',
|
||||
'fqdn/%s.yaml' % p['fqdn'] ] + ['group/%s.yaml' % f for f in p['groups'] ]})
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
main()
|
@ -1,4 +1,51 @@
|
||||
---
|
||||
- name: ensure hiera datadir
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ hieradata }}/{{ hieraenvironment }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0700
|
||||
when: copy_hieradata
|
||||
- name: ensure hiera datadir - fqdn
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ hieradata }}/{{ hieraenvironment }}/fqdn"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0700
|
||||
when: copy_hieradata
|
||||
- name: ensure hiera datadir - group
|
||||
file:
|
||||
state: directory
|
||||
path: "{{ hieradata }}/{{ hieraenvironment }}/group"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0700
|
||||
when: copy_hieradata
|
||||
- name: make file list
|
||||
puppet_get_hiera_file_list:
|
||||
fqdn: "{{ ansible_fqdn }}"
|
||||
groups: "{{ hostvars[inventory_hostname].group_names }}"
|
||||
register: hiera_file_paths
|
||||
- debug: msg="System {{hiera_file_paths.paths_dict.paths}}"
|
||||
- name: find which files exist
|
||||
stat:
|
||||
path: "{{ hieradata }}/{{ hieraenvironment }}/{{ item }}"
|
||||
register: st
|
||||
with_items: hiera_file_paths.paths_dict.paths
|
||||
delegate_to: localhost
|
||||
when: copy_hieradata
|
||||
- debug: msg="System {{st}}"
|
||||
- name: copy hiera files
|
||||
when: copy_hieradata and item.1.stat.exists
|
||||
copy:
|
||||
src: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
||||
dest: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
||||
mode: 0600
|
||||
with_together:
|
||||
- hiera_file_paths.paths_dict.paths
|
||||
- st.results
|
||||
- name: run puppet
|
||||
puppet:
|
||||
puppetmaster: "{{ puppetmaster|default(omit) }}"
|
||||
|
@ -1,2 +1,5 @@
|
||||
---
|
||||
# vars file for ansible-puppet
|
||||
hieradata: /etc/puppet/hieradata
|
||||
hieraenvironment: production
|
||||
copy_hieradata: False
|
||||
|
Loading…
x
Reference in New Issue
Block a user