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. We also don't need to hardcode the various config paths in
config or manage environments since we're using the defaults and
hardcoding them would make them incorrect for one or the other puppet
versions.

Change-Id: I164f91f9a7942e8c5f059652634ec1078ae41aae
This commit is contained in:
Colleen Murphy 2018-04-18 00:20:13 +02:00 committed by Colleen Murphy
parent edb0e245d5
commit ed9e2bebf2
6 changed files with 63 additions and 34 deletions

View File

@ -2,7 +2,6 @@
# defaults file for ansible-puppet # defaults file for ansible-puppet
copy_hieradata: false copy_hieradata: false
copy_puppet: false copy_puppet: false
hieradata: /etc/puppet/hieradata
# #
manage_config: False manage_config: False
@ -10,9 +9,6 @@ puppet_server: puppet
certname: "{{ ansible_fqdn }}" certname: "{{ ansible_fqdn }}"
puppet_data_binding_terminus: hiera puppet_data_binding_terminus: hiera
puppet_reports: store puppet_reports: store
puppet_basemodulepath: '$confdir/modules'
puppet_environmentpath: '$confdir/environments'
puppet_hiera_datadir: '/opt/system-config/' puppet_hiera_datadir: '/opt/system-config/'
puppet_environment_basedir: '/opt/system-config/'
puppet_environment: production puppet_environment: production
puppet_timeout: 30m puppet_timeout: 30m

View File

@ -59,7 +59,7 @@ def main():
for path in paths: for path in paths:
full_path = os.path.join(p['location'], path) full_path = os.path.join(p['location'], path)
if os.path.exists(full_path): if os.path.exists(full_path):
good_paths.append(full_path) good_paths.append(path)
module.exit_json(paths=good_paths) 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 # Create our config
- name: Create puppet.conf from template - name: Create puppet.conf from template
template: template:
src: "puppet.conf.j2" src: "puppet.conf.j2"
dest: "/etc/puppet/puppet.conf" dest: "{{ puppet_confdir }}/puppet.conf"
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
@ -11,7 +19,7 @@
- name: Create hiera.yaml from template - name: Create hiera.yaml from template
template: template:
src: "hiera.yaml.j2" src: "hiera.yaml.j2"
dest: "/etc/puppet/hiera.yaml" dest: "{{ puppet_confdir }}/hiera.yaml"
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
@ -24,21 +32,4 @@
group: root group: root
state: link state: link
force: yes force: yes
when: puppet_version == '3'
- name: create environment directory
file:
path: "/etc/puppet/environments/{{ puppet_environment }}"
state: directory
owner: root
group: root
mode: 0755
when: puppet_environment is defined
- name: create environment.conf from template
template:
src: "environment.conf.j2"
dest: "/etc/puppet/environments/{{ puppet_environment }}/environment.conf"
owner: root
group: root
mode: 0644
when: puppet_environment is defined

View File

@ -1,9 +1,45 @@
--- ---
- name: Get management server puppet version
shell:
cmd: "puppet --version | cut -d '.' -f 1"
delegate_to: localhost
register: mgmt_puppet_version
- name: Set management server puppet version fact
set_fact:
mgmt_puppet_version: "{{ mgmt_puppet_version.stdout }}"
- name: Sanity check management server puppet version
fail: "Unsupported puppet version {{ mgmt_puppet_version }}"
when: (mgmt_puppet_version != 3 and mgmt_puppet_version != 4)
- name: Get puppet version
shell:
cmd: "puppet --version | cut -d '.' -f 1"
register: puppet_version
- name: Set puppet version fact
set_fact:
puppet_version: "{{ puppet_version.stdout }}"
- name: Sanity check puppet version
fail: "Unsupported puppet version {{ puppet_version }}"
when: (puppet_version != 3 and puppet_version != 4)
- block: - 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 - name: ensure hiera directory
file: file:
state: directory state: directory
path: "{{ hieradata }}/{{ puppet_environment }}/{{ item }}" path: "{{ hieradata }}//{{ item }}"
owner: root owner: root
group: root group: root
mode: 0700 mode: 0700
@ -15,14 +51,14 @@
puppet_get_hiera_file_list: puppet_get_hiera_file_list:
fqdn: "{{ ansible_fqdn }}" fqdn: "{{ ansible_fqdn }}"
groups: "{{ hostvars[inventory_hostname].group_names }}" groups: "{{ hostvars[inventory_hostname].group_names }}"
location: "{{ hieradata }}/{{ puppet_environment }}" location: "{{ hieradata }}"
delegate_to: localhost delegate_to: localhost
register: hiera_file_paths register: hiera_file_paths
- name: copy hiera files - name: copy hiera files
copy: copy:
src: "{{ item }}" src: "{{ mgmt_hieradata + '/' + item }}"
dest: "{{ item }}" dest: "{{ hieradata + '/' item }}"
mode: 0600 mode: 0600
with_items: "{{ hiera_file_paths.paths|default() }}" with_items: "{{ hiera_file_paths.paths|default() }}"
@ -41,10 +77,19 @@
state: link state: link
when: copy_hieradata 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' if puppet_version == '3' else '/etc/puppetlabs/code' }}"
- name: copy system puppet modules - name: copy system puppet modules
synchronize: synchronize:
src: /etc/puppet/modules src: "{{ mgmt_puppet_module_dir }}"
dest: /etc/puppet dest: "{{ puppet_module_dir }}"
when: when:
- copy_puppet - copy_puppet

View File

@ -1 +0,0 @@
modulepath = '{{ puppet_basemodulepath }}:{{ puppet_environment_basedir }}{{ puppet_environment }}/modules'

View File

@ -8,8 +8,6 @@ certname={{ certname }}
pluginsync=true pluginsync=true
data_binding_terminus={{ puppet_data_binding_terminus }} data_binding_terminus={{ puppet_data_binding_terminus }}
reports={{ puppet_reports }} reports={{ puppet_reports }}
basemodulepath = {{ puppet_basemodulepath }}
environmentpath={{ puppet_environmentpath }}
environmenttimeout=0 environmenttimeout=0
[master] [master]