Don't hardcode puppet-3-specific config paths

This patch ensures that hiera data and puppet modules, and puppet config
are copied to the right directory depending on the current puppet
version. Since it's possible for the ansible management server and the
managed nodes to have different puppet versions, we need to account for
the possibility that the source and destination paths might be
different.

Change-Id: I164f91f9a7942e8c5f059652634ec1078ae41aae
This commit is contained in:
Colleen Murphy 2018-04-18 00:20:13 +02:00
parent edb0e245d5
commit cbfdcbfc58
4 changed files with 54 additions and 12 deletions

View File

@ -2,7 +2,6 @@
# defaults file for ansible-puppet
copy_hieradata: false
copy_puppet: false
hieradata: /etc/puppet/hieradata
#
manage_config: False

View File

@ -59,7 +59,7 @@ def main():
for path in paths:
full_path = os.path.join(p['location'], path)
if os.path.exists(full_path):
good_paths.append(full_path)
good_paths.append(path)
module.exit_json(paths=good_paths)

View File

@ -1,9 +1,17 @@
---
- name: Set puppet conf dir
set_fact:
puppet_confdir: "{{ '/etc/puppet if puppet_version == '3' else '/etc/puppetlabs/puppet' }}"
- name: Set puppet code dir
set_fact:
puppet_codedir: "{{ '/etc/puppet if puppet_version == '3' else '/etc/puppetlabs/code' }}"
# Create our config
- name: Create puppet.conf from template
template:
src: "puppet.conf.j2"
dest: "/etc/puppet/puppet.conf"
dest: "{{ puppet_confdir }}/puppet.conf"
owner: root
group: root
mode: 0644
@ -11,7 +19,7 @@
- name: Create hiera.yaml from template
template:
src: "hiera.yaml.j2"
dest: "/etc/puppet/hiera.yaml"
dest: "{{ puppet_confdir }}/hiera.yaml"
owner: root
group: root
mode: 0644
@ -24,10 +32,11 @@
group: root
state: link
force: yes
when: puppet_version == '3'
- name: create environment directory
file:
path: "/etc/puppet/environments/{{ puppet_environment }}"
path: "{{ puppet_codedir }}/environments/{{ puppet_environment }}"
state: directory
owner: root
group: root
@ -37,7 +46,7 @@
- name: create environment.conf from template
template:
src: "environment.conf.j2"
dest: "/etc/puppet/environments/{{ puppet_environment }}/environment.conf"
dest: "{{ puppet_codedir }}/environments/{{ puppet_environment }}/environment.conf"
owner: root
group: root
mode: 0644

View File

@ -1,9 +1,32 @@
---
- name: Get management server puppet version
shell:
cmd: "puppet --version | cut -d '.' -f 1"
delegate_to: localhost
register: mgmt_puppet_version
- name: Get puppet version
shell:
cmd: "puppet --version | cut -d '.' -f 1"
register: puppet_version
- debug: var=mgmt_puppet_version
- debug: var=puppet_version
- block:
- name: Set management server hieradata var
set_fact:
mgmt_hieradata: "{{ '/etc/puppet/hieradata' + puppet_environment if mgmt_puppet_version == '3' else '/etc/puppetlabs/code/environments/' + puppet_environment + '/hieradata' }}"
delegate_to: localhost
- name: Set hieradata var
set_fact:
hieradata: "{{ '/etc/puppet/hieradata' + puppet_environment if puppet_version == '3' else '/etc/puppetlabs/code/environments/' + puppet_environment + '/hieradata' }}"
- name: ensure hiera directory
file:
state: directory
path: "{{ hieradata }}/{{ puppet_environment }}/{{ item }}"
path: "{{ hieradata }}//{{ item }}"
owner: root
group: root
mode: 0700
@ -15,14 +38,14 @@
puppet_get_hiera_file_list:
fqdn: "{{ ansible_fqdn }}"
groups: "{{ hostvars[inventory_hostname].group_names }}"
location: "{{ hieradata }}/{{ puppet_environment }}"
location: "{{ hieradata }}"
delegate_to: localhost
register: hiera_file_paths
- name: copy hiera files
copy:
src: "{{ item }}"
dest: "{{ item }}"
src: "{{ mgmt_hieradata + '/' + item }}"
dest: "{{ hieradata + '/' item }}"
mode: 0600
with_items: "{{ hiera_file_paths.paths|default() }}"
@ -41,10 +64,19 @@
state: link
when: copy_hieradata
- name: Set management server puppet module dir
set_fact:
mgmt_puppet_module_dir: "{{ '/etc/puppet/modules' if mgmt_puppet_version == '3' else '/etc/puppetlabs/code/modules' }}"
delegate_to: localhost
- name: Set puppet module dir
set_fact:
puppet_module_dir: "{{ '/etc/puppet/modules' if puppet_version == '3' else '/etc/puppetlabs/code/modules' }}"
- name: copy system puppet modules
synchronize:
src: /etc/puppet/modules
dest: /etc/puppet
src: "{{ mgmt_puppet_module_dir }}"
dest: "{{ puppet_module_dir }}"
when:
- copy_puppet
@ -53,6 +85,8 @@
- name: setup config files
when: manage_config|bool
include: config.yml
vars:
puppet_version: puppet_version
- block:
- name: run puppet