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:
parent
edb0e245d5
commit
330d2b5c20
|
@ -2,7 +2,6 @@
|
|||
# defaults file for ansible-puppet
|
||||
copy_hieradata: false
|
||||
copy_puppet: false
|
||||
hieradata: /etc/puppet/hieradata
|
||||
#
|
||||
|
||||
manage_config: False
|
||||
|
@ -10,9 +9,6 @@ puppet_server: puppet
|
|||
certname: "{{ ansible_fqdn }}"
|
||||
puppet_data_binding_terminus: hiera
|
||||
puppet_reports: store
|
||||
puppet_basemodulepath: '$confdir/modules'
|
||||
puppet_environmentpath: '$confdir/environments'
|
||||
puppet_hiera_datadir: '/opt/system-config/'
|
||||
puppet_environment_basedir: '/opt/system-config/'
|
||||
puppet_environment: production
|
||||
puppet_timeout: 30m
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,21 +32,4 @@
|
|||
group: root
|
||||
state: link
|
||||
force: yes
|
||||
|
||||
- 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
|
||||
when: puppet_version == '3'
|
||||
|
|
|
@ -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:
|
||||
- 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 +51,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 +77,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' if puppet_version == '3' else '/etc/puppetlabs/code' }}"
|
||||
|
||||
- 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
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
modulepath = '{{ puppet_basemodulepath }}:{{ puppet_environment_basedir }}{{ puppet_environment }}/modules'
|
|
@ -8,8 +8,6 @@ certname={{ certname }}
|
|||
pluginsync=true
|
||||
data_binding_terminus={{ puppet_data_binding_terminus }}
|
||||
reports={{ puppet_reports }}
|
||||
basemodulepath = {{ puppet_basemodulepath }}
|
||||
environmentpath={{ puppet_environmentpath }}
|
||||
environmenttimeout=0
|
||||
|
||||
[master]
|
||||
|
|
Loading…
Reference in New Issue