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
parent edb0e245d5
commit 4d64868882
6 changed files with 91 additions and 17 deletions

View File

@ -10,8 +10,8 @@ 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_basemodulepath: ''
puppet_environmentpath: '$confdir/environments' puppet_environmentpath: ''
puppet_hiera_datadir: '/opt/system-config/' puppet_hiera_datadir: '/opt/system-config/'
puppet_environment_basedir: '/opt/system-config/' puppet_environment_basedir: '/opt/system-config/'
puppet_environment: production puppet_environment: production

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,22 @@
--- ---
- 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' }}"
- name: Enable puppet environments explicitly for puppet 3
set_fact:
puppet_environmentpath: '$confdir/environments'
when: puppet_version == '3' and puppet_environmentpath == ''
# 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,14 +24,14 @@
- 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
- name: symlink hiera config files together - name: symlink hiera config files together
file: file:
src: "/etc/puppet/hiera.yaml" src: "{{ puppet_confdir }}/hiera.yaml"
dest: "/etc/hiera.yaml" dest: "/etc/hiera.yaml"
owner: root owner: root
group: root group: root
@ -27,7 +40,7 @@
- name: create environment directory - name: create environment directory
file: file:
path: "/etc/puppet/environments/{{ puppet_environment }}" path: "{{ puppet_codedir }}/environments/{{ puppet_environment }}"
state: directory state: directory
owner: root owner: root
group: root group: root
@ -37,7 +50,7 @@
- name: create environment.conf from template - name: create environment.conf from template
template: template:
src: "environment.conf.j2" src: "environment.conf.j2"
dest: "/etc/puppet/environments/{{ puppet_environment }}/environment.conf" dest: "{{ puppet_codedir }}/environments/{{ puppet_environment }}/environment.conf"
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644

View File

@ -1,9 +1,45 @@
--- ---
- name: Get management server puppet version
shell:
cmd: "PATH=$PATH:/opt/puppetlabs/bin 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: "PATH=$PATH:/opt/puppetlabs/bin 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,31 @@
state: link state: link
when: copy_hieradata when: copy_hieradata
- name: Set management server puppet module dir to user-defined path
set_fact:
mgmt_puppet_module_dir: "{{ puppet_basemodulepath }}"
when: puppet_basemodulepath != ''
- 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
when: mgmt_puppet_module_dir is not defined
- name: Set puppet module dir to user-defined path
set_fact:
puppet_module_dir: "{{ puppet_basemodulepath }}"
when: puppet_basemodulepath != ''
- name: Set puppet module dir
set_fact:
puppet_module_dir: "{{ '/etc/puppet' if puppet_version == '3' else '/etc/puppetlabs/code' }}"
when: puppet_module_dir is not defined
- 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 +1 @@
modulepath = '{{ puppet_basemodulepath }}:{{ puppet_environment_basedir }}{{ puppet_environment }}/modules' modulepath = {{ puppet_basemodulepath if puppet_basemodulepath != '' else '$basemodulepath' }}:$environmentpath/{{ puppet_environment }}/modules:{{ puppet_environment_basedir if puppet_environment_basedir != '' else '$environmentpath' }}/{{ puppet_environment }}/modules

View File

@ -8,9 +8,13 @@ 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
{% if puppet_basemodulepath != '' %}
basemodulepath = {{ puppet_basemodulepath }}
{% endif %}
{% if puppet_environmentpath != '' %}
environmentpath={{ puppet_environmentpath }}
{% endif %}
[master] [master]
# These are needed when the puppetmaster is run by passenger # These are needed when the puppetmaster is run by passenger