aboutsummaryrefslogtreecommitdiff
path: root/personal_infra/playbooks/apply_puppet.yml
blob: 15ee4ebf6cbd45b25b34cd13063c4a60478def7e (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
---
- name: apply puppet config
  hosts: all
  collections:
    - ansible.builtin
    - community.general

  tasks:
    - name: install puppet
      package:
        name: puppet
    - name: create local temporary directory
      tempfile:
        state: directory
      register: local_temp
      delegate_to: 127.0.0.1
    - name: create remote temporary directory
      tempfile:
        state: directory
      register: remote_temp
    - name: package manifests
      archive:
        path: ../puppet
        dest: "{{ local_temp.path }}/puppet.tar.gz"
      delegate_to: 127.0.0.1
    - name: unpackage manifests
      unarchive:
        src: "{{ local_temp.path }}/puppet.tar.gz"
        dest: "{{ remote_temp.path }}"
    - name: dump variables
      copy:
        dest: "{{ remote_temp.path }}/vars.json"
        content: "{{ hostvars }}"
    - name: create hiera.yaml
      copy:
        dest: "{{ remote_temp.path }}/hiera.yaml"
        content: |
          version: 5
          hierarchy:
            - name: ansible
              datadir: {{ remote_temp.path }}
              path: vars.json
              data_hash: json_data
    - name: run puppet
      command: puppet apply {{ remote_temp.path }} --modulepath={{ remote_temp.path }}/puppet/modules --hiera_config={{ remote_temp.path }}/hiera.yaml
      environment:
        FACTER_ansible_inventory_hostname: "{{ inventory_hostname }}"
    - name: clean up local temporary directory
      file:
        state: absent
        path: "{{ local_temp.path}}"
      delegate_to: 127.0.0.1
    - name: clean up remote temporary directory
      file:
        state: absent
        path: "{{ remote_temp.path }}"