Browse Source

Merge "Don't hardcode puppet-3-specific config paths"

Zuul 1 year ago
parent
commit
d5dbfc3a62

+ 2
- 2
defaults/main.yml View File

@@ -10,8 +10,8 @@ puppet_server: puppet
10 10
 certname: "{{ ansible_fqdn }}"
11 11
 puppet_data_binding_terminus: hiera
12 12
 puppet_reports: store
13
-puppet_basemodulepath: '$confdir/modules'
14
-puppet_environmentpath: '$confdir/environments'
13
+puppet_basemodulepath: ''
14
+puppet_environmentpath: ''
15 15
 puppet_hiera_datadir: '/opt/system-config/'
16 16
 puppet_environment_basedir: '/opt/system-config/'
17 17
 puppet_environment: production

+ 1
- 1
library/puppet_get_hiera_file_list View File

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

+ 18
- 5
tasks/config.yml View File

@@ -1,9 +1,22 @@
1 1
 ---
2
+- name: Set puppet conf dir
3
+  set_fact:
4
+      puppet_confdir: "{{ '/etc/puppet' if puppet_version == '3' else '/etc/puppetlabs/puppet' }}"
5
+
6
+- name: Set puppet code dir
7
+  set_fact:
8
+      puppet_codedir: "{{ '/etc/puppet' if puppet_version == '3' else '/etc/puppetlabs/code' }}"
9
+
10
+- name: Enable puppet environments explicitly for puppet 3
11
+  set_fact:
12
+    puppet_environmentpath: '$confdir/environments'
13
+  when: puppet_version == '3' and puppet_environmentpath == ''
14
+
2 15
 # Create our config
3 16
 - name: Create puppet.conf from template
4 17
   template:
5 18
     src: "puppet.conf.j2"
6
-    dest: "/etc/puppet/puppet.conf"
19
+    dest: "{{ puppet_confdir }}/puppet.conf"
7 20
     owner: root
8 21
     group: root
9 22
     mode: 0644
@@ -11,14 +24,14 @@
11 24
 - name: Create hiera.yaml from template
12 25
   template:
13 26
     src: "hiera.yaml.j2"
14
-    dest: "/etc/puppet/hiera.yaml"
27
+    dest: "{{ puppet_confdir }}/hiera.yaml"
15 28
     owner: root
16 29
     group: root
17 30
     mode: 0644
18 31
 
19 32
 - name: symlink hiera config files together
20 33
   file:
21
-    src: "/etc/puppet/hiera.yaml"
34
+    src: "{{ puppet_confdir }}/hiera.yaml"
22 35
     dest: "/etc/hiera.yaml"
23 36
     owner: root
24 37
     group: root
@@ -27,7 +40,7 @@
27 40
 
28 41
 - name: create environment directory
29 42
   file:
30
-    path: "/etc/puppet/environments/{{ puppet_environment }}"
43
+    path: "{{ puppet_codedir }}/environments/{{ puppet_environment }}"
31 44
     state: directory
32 45
     owner: root
33 46
     group: root
@@ -37,7 +50,7 @@
37 50
 - name: create environment.conf from template
38 51
   template:
39 52
     src: "environment.conf.j2"
40
-    dest: "/etc/puppet/environments/{{ puppet_environment }}/environment.conf"
53
+    dest: "{{ puppet_codedir }}/environments/{{ puppet_environment }}/environment.conf"
41 54
     owner: root
42 55
     group: root
43 56
     mode: 0644

+ 63
- 6
tasks/main.yml View File

@@ -1,9 +1,45 @@
1 1
 ---
2
+- name: Get management server puppet version
3
+  shell:
4
+    cmd: "PATH=$PATH:/opt/puppetlabs/bin puppet --version | cut -d '.' -f 1"
5
+  delegate_to: localhost
6
+  register: mgmt_puppet_version
7
+
8
+- name: Set management server puppet version fact
9
+  set_fact:
10
+    mgmt_puppet_version: "{{ mgmt_puppet_version.stdout }}"
11
+
12
+- name: Sanity check management server puppet version
13
+  fail: "Unsupported puppet version {{ mgmt_puppet_version }}"
14
+  when: (mgmt_puppet_version != '3' and mgmt_puppet_version != '4')
15
+
16
+- name: Get puppet version
17
+  shell:
18
+    cmd: "PATH=$PATH:/opt/puppetlabs/bin puppet --version | cut -d '.' -f 1"
19
+  register: puppet_version
20
+
21
+- name: Set puppet version fact
22
+  set_fact:
23
+    puppet_version: "{{ puppet_version.stdout }}"
24
+
25
+- name: Sanity check puppet version
26
+  fail: "Unsupported puppet version {{ puppet_version }}"
27
+  when: (puppet_version != '3' and puppet_version != '4')
28
+
2 29
 - block:
30
+  - name: Set management server hieradata var
31
+    set_fact:
32
+      mgmt_hieradata: "{{ '/etc/puppet/hieradata' + puppet_environment if mgmt_puppet_version == '3' else '/etc/puppetlabs/code/environments/' + puppet_environment + '/hieradata' }}"
33
+    delegate_to: localhost
34
+
35
+  - name: Set hieradata var
36
+    set_fact:
37
+      hieradata: "{{ '/etc/puppet/hieradata' + puppet_environment if puppet_version == '3' else '/etc/puppetlabs/code/environments/' + puppet_environment + '/hieradata' }}"
38
+
3 39
   - name: ensure hiera directory
4 40
     file:
5 41
       state: directory
6
-      path: "{{ hieradata }}/{{ puppet_environment }}/{{ item }}"
42
+      path: "{{ hieradata }}//{{ item }}"
7 43
       owner: root
8 44
       group: root
9 45
       mode: 0700
@@ -15,14 +51,14 @@
15 51
     puppet_get_hiera_file_list:
16 52
       fqdn: "{{ ansible_fqdn }}"
17 53
       groups: "{{ hostvars[inventory_hostname].group_names }}"
18
-      location: "{{ hieradata }}/{{ puppet_environment }}"
54
+      location: "{{ hieradata }}"
19 55
     delegate_to: localhost
20 56
     register: hiera_file_paths
21 57
 
22 58
   - name: copy hiera files
23 59
     copy:
24
-      src: "{{ item }}"
25
-      dest: "{{ item }}"
60
+      src: "{{ mgmt_hieradata + '/' + item }}"
61
+      dest: "{{ hieradata + '/' item }}"
26 62
       mode: 0600
27 63
     with_items: "{{ hiera_file_paths.paths|default() }}"
28 64
 
@@ -41,10 +77,31 @@
41 77
       state: link
42 78
     when: copy_hieradata
43 79
 
80
+  - name: Set management server puppet module dir to user-defined path
81
+    set_fact:
82
+      mgmt_puppet_module_dir: "{{ puppet_basemodulepath }}"
83
+    when: puppet_basemodulepath != ''
84
+
85
+  - name: Set management server puppet module dir
86
+    set_fact:
87
+      mgmt_puppet_module_dir: "{{ '/etc/puppet/modules' if mgmt_puppet_version == '3' else '/etc/puppetlabs/code/modules' }}"
88
+    delegate_to: localhost
89
+    when: mgmt_puppet_module_dir is not defined
90
+
91
+  - name: Set puppet module dir to user-defined path
92
+    set_fact:
93
+      puppet_module_dir: "{{ puppet_basemodulepath }}"
94
+    when: puppet_basemodulepath != ''
95
+
96
+  - name: Set puppet module dir
97
+    set_fact:
98
+      puppet_module_dir: "{{ '/etc/puppet' if puppet_version == '3' else '/etc/puppetlabs/code' }}"
99
+    when: puppet_module_dir is not defined
100
+
44 101
   - name: copy system puppet modules
45 102
     synchronize:
46
-      src: /etc/puppet/modules
47
-      dest: /etc/puppet
103
+      src: "{{ mgmt_puppet_module_dir }}"
104
+      dest: "{{ puppet_module_dir }}"
48 105
 
49 106
   when:
50 107
   - copy_puppet

+ 1
- 1
templates/environment.conf.j2 View File

@@ -1 +1 @@
1
-modulepath = '{{ puppet_basemodulepath }}:{{ puppet_environment_basedir }}{{ puppet_environment }}/modules'
1
+modulepath = {{ puppet_basemodulepath if puppet_basemodulepath != '' else '$basemodulepath' }}:$environmentpath/{{ puppet_environment }}/modules:{{ puppet_environment_basedir if puppet_environment_basedir != '' else '$environmentpath' }}/{{ puppet_environment }}/modules

+ 5
- 1
templates/puppet.conf.j2 View File

@@ -8,9 +8,13 @@ certname={{ certname }}
8 8
 pluginsync=true
9 9
 data_binding_terminus={{ puppet_data_binding_terminus }}
10 10
 reports={{ puppet_reports }}
11
+environmenttimeout=0
12
+{% if puppet_basemodulepath != '' %}
11 13
 basemodulepath = {{ puppet_basemodulepath }}
14
+{% endif %}
15
+{% if puppet_environmentpath != '' %}
12 16
 environmentpath={{ puppet_environmentpath }}
13
-environmenttimeout=0
17
+{% endif %}
14 18
 
15 19
 [master]
16 20
 # These are needed when the puppetmaster is run by passenger

Loading…
Cancel
Save