aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/playbooks/roles/apply_puppet/tasks/main.yml
blob: 3512717ee2763185fa46cc320d97892cfe6d455b (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
---
- name: clean puppet build directory
  local_action:
    module: file
    path: "{{ inventory_dir }}/build/puppet"
    state: absent
  run_once: True
  tags: puppet_fast
- name: create puppet build directories
  local_action:
    module: file
    path: "{{ inventory_dir }}/{{ item }}"
    state: directory
  loop:
    - build/puppet/global_vars
    - build/puppet/host_vars
    - build/puppet/facts
  run_once: True
  tags: puppet_fast
- name: create puppet build host vars directories
  local_action:
    module: file
    path: "{{ inventory_dir }}/build/puppet/host_vars/{{ inventory_hostname }}"
    state: directory
  tags: puppet_fast
- name: dump hostvars
  local_action:
    module: copy
    dest: "{{ inventory_dir }}/build/puppet/global_vars/hostvars.json"
    content: "{'hostvars': {{ hostvars }} }"
  run_once: True
  tags: puppet_fast
- name: dump this
  local_action:
    module: copy
    dest: "{{ inventory_dir }}/build/puppet/host_vars/{{ inventory_hostname }}/this.json"
    content: "{{ hostvars[inventory_hostname] }}"
  tags: puppet_fast
- name: get facts
  command: facter -y
  register: facter_output
  tags: puppet_fast
- name: dump facts
  local_action:
    module: copy
    dest: "{{ inventory_dir }}/build/puppet/facts/{{ inventory_hostname }}.yaml"
    content: "{{ facter_output.stdout }}"
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: compile puppet catalogs
  local_action:
    module: command
    cmd: "{{ inventory_dir }}/up.py {{ inventory_dir }}/build/puppet {{ inventory_dir }}/puppet/modules {{ inventory_dir }}/puppet/site {% for host in ansible_play_batch %}{{ host }} {% endfor %}"
  tags: puppet_fast
  run_once: True
- name: package catalog
  archive:
    path: "{{ inventory_dir }}/build/puppet/build/output/{{ inventory_hostname }}"
    dest: "{{ inventory_dir }}/build/puppet/puppet_catalog_{{ inventory_hostname }}.zip"
    format: zip
  delegate_to: 127.0.0.1
  tags: puppet_fast
- name: create remote temporary directory
  tempfile:
    state: directory
  register: remote_temp
  tags: puppet_fast
- name: unpackage catalog
  unarchive:
    src: "{{ inventory_dir }}/build/puppet/puppet_catalog_{{ inventory_hostname }}.zip"
    dest: "{{ remote_temp.path }}"
  tags: puppet_fast
- name: preview catalog
  command: puppet apply --catalog {{ remote_temp.path }}/{{ inventory_hostname }}/catalog.json --noop --test --modulepath={{ remote_temp.path }}/{{ inventory_hostname }}/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 }}/{{ inventory_hostname }}/catalog.json --modulepath={{ remote_temp.path }}/{{ inventory_hostname }}/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: "{{ inventory_dir }}/build/puppet/"
  delegate_to: 127.0.0.1
  tags: puppet_fast
  run_once: True