aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/playbooks/roles/apply_puppet/tasks/main.yml
blob: 0ee291ef6d959f2331341ced5ef5c2d13d9e8885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
- name: create local temporary directory
  tempfile:
    state: directory
    path: "{{ inventory_dir }}/tmp"
  register: local_temp
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: create data directory in local temp
  file:
    path: "{{ local_temp.path }}/data"
    state: directory
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: create hiera.yaml
  copy:
    dest: "{{ local_temp.path }}/hiera.yaml"
    content: |
      version: 5
      hierarchy:
        - name: hostvars
          path: hostvars.json
          data_hash: json_data
        - name: this
          path: this.json
          data_hash: json_data
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: dump hostvars
  copy:
    dest: "{{ local_temp.path }}/data/hostvars.json"
    content: "{'hostvars': {{ hostvars }} }"
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: dump this
  copy:
    dest: "{{ local_temp.path }}/data/this.json"
    content: "{{ hostvars[inventory_hostname] }}"
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: install epel
  package:
    name: epel-release
  when: ansible_distribution_file_variety == 'RedHat'
- name: install packages
  package:
    name:
      - puppet
      - unzip
- name: get facts
  command: facter -y
  register: facter_output
  tags: puppet_fast
- name: create facts directory in local temp
  file:
    path: "{{ local_temp.path }}/yaml/facts"
    state: directory
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: dump facts
  copy:
    dest: "{{ local_temp.path }}/yaml/facts/{{ inventory_hostname }}.yaml"
    content: "--- !ruby/object:Puppet::Node::Facts\nvalues:\n  {{ facter_output.stdout | indent(width=2) }}"
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: compile catalogs
  command: puppet catalog compile --modulepath={{ inventory_dir }}/puppet/modules --hiera_config={{ local_temp.path }}/hiera.yaml --manifest={{ inventory_dir }}/puppet/site --terminus compiler --vardir {{ local_temp.path }}/ --facts_terminus yaml {{ inventory_hostname }}
  delegate_to: 127.0.0.1
  register: catalog
  tags: puppet_fast
- name: create remote temporary directory
  tempfile:
    state: directory
  register: remote_temp
  tags: puppet_fast
- name: write catalog
  copy:
    dest: "{{ remote_temp.path }}/catalog.json"
    content: "{{ catalog.stdout | regex_replace('\\A.*?\\n', multiline=True) }}"
  tags: puppet_fast
- name: package modules
  archive:
    path: ../puppet/modules
    dest: "{{ local_temp.path }}/puppet_modules.zip"
    format: zip
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: unpackage modules
  unarchive:
    src: "{{ local_temp.path }}/puppet_modules.zip"
    dest: "{{ remote_temp.path }}"
  tags: puppet_fast
- name: preview catalog
  command: puppet apply --catalog {{ remote_temp.path }}/catalog.json --noop --test --modulepath={{ remote_temp.path }}/modules/
  register: catalog_apply
  tags: puppet_fast
- name: display catalog preview stdout
  debug:
    msg: "{{ catalog_apply.stdout_lines }}"
  tags: puppet_fast
- name: display catalog preview stderr
  debug:
    msg: "{{ catalog_apply.stderr_lines }}"
  tags: puppet_fast
- name: pause to confirm
  pause:
  tags: pause
- name: apply catalog
  command: puppet apply --catalog {{ remote_temp.path }}/catalog.json --modulepath={{ remote_temp.path }}/modules/
  register: catalog_apply
  tags: puppet_fast
- name: display catalog apply stdout
  debug:
    msg: "{{ catalog_apply.stdout_lines }}"
  tags: puppet_fast
- name: display catalog apply stderr
  debug:
    msg: "{{ catalog_apply.stderr_lines }}"
  tags: puppet_fast
- name: clean up remote temporary directory
  file:
    state: absent
    path: "{{ remote_temp.path }}"
  tags: puppet_fast
- name: clean up local temporary directory
  file:
    state: absent
    path: "{{ local_temp.path}}"
  delegate_to: 127.0.0.1
  tags: puppet_fast