|
| 1 | +--- |
| 2 | +- name: Check registration of host |
| 3 | + stat: |
| 4 | + path: /etc/icinga2/pki/ca.crt |
| 5 | + register: st |
| 6 | + |
| 7 | +- set_fact: |
| 8 | + pki_configured: true |
| 9 | + when: st.stat.isfile is defined and st.stat.isfile |
| 10 | + |
| 11 | +- set_fact: |
| 12 | + pki_configured: false |
| 13 | + when: st.stat.isfile is not defined or not st.stat.isfile |
| 14 | + |
| 15 | +- block: |
| 16 | + - name: Create pki directory |
| 17 | + file: |
| 18 | + dest: /etc/icinga2/pki |
| 19 | + state: directory |
| 20 | + owner: icinga |
| 21 | + group: icinga |
| 22 | + mode: 0700 |
| 23 | + |
| 24 | + - name: Create local cert |
| 25 | + command: > |
| 26 | + icinga2 pki new-cert |
| 27 | + --cn "{{ inventory_hostname }}" |
| 28 | + --key /etc/icinga2/pki/{{ inventory_hostname }}.key |
| 29 | + --cert /etc/icinga2/pki/{{ inventory_hostname }}.crt |
| 30 | + args: |
| 31 | + creates: /etc/icinga2/pki/{{ inventory_hostname }}.key |
| 32 | + |
| 33 | + - name: Set trusted master certificate |
| 34 | + command: > |
| 35 | + icinga2 pki save-cert |
| 36 | + --key /etc/icinga2/pki/{{ inventory_hostname }}.key |
| 37 | + --cert /etc/icinga2/pki/{{ inventory_hostname }}.crt |
| 38 | + --trustedcert /etc/icinga2/pki/trusted-master.crt |
| 39 | + --host {{ icinga2_master }} |
| 40 | + args: |
| 41 | + creates: /etc/icinga2/pki/trusted-master.crt |
| 42 | + |
| 43 | + - name: Request Icinga2 ticket |
| 44 | + command: > |
| 45 | + icinga2 pki ticket |
| 46 | + --cn "{{ inventory_hostname }}" |
| 47 | + register: key |
| 48 | + delegate_to: "{{ icinga2_master }}" |
| 49 | + |
| 50 | + - name: Request PKI |
| 51 | + command: > |
| 52 | + icinga2 pki request |
| 53 | + --host {{ icinga2_master }} |
| 54 | + --port 5665 |
| 55 | + --ticket {{ key.stdout }} |
| 56 | + --key /etc/icinga2/pki/{{ inventory_hostname }}.key |
| 57 | + --cert /etc/icinga2/pki/{{ inventory_hostname }}.crt |
| 58 | + --trustedcert /etc/icinga2/pki/trusted-master.crt |
| 59 | + --ca /etc/icinga2/pki/ca.crt |
| 60 | + args: |
| 61 | + creates: /etc/icinga2/pki/ca.crt |
| 62 | + |
| 63 | + - name: Setup Icinga as satellite node |
| 64 | + command: > |
| 65 | + icinga2 node setup |
| 66 | + --cn {{ inventory_hostname }} |
| 67 | + --ticket {{ key.stdout }} |
| 68 | + --endpoint "{{ icinga2_master }}" |
| 69 | + --master_host "{{ icinga2_master }}" |
| 70 | + --zone "{{ inventory_hostname }}" |
| 71 | + --trustedcert /etc/icinga2/pki/trusted-master.crt |
| 72 | + --accept-config |
| 73 | + --accept-commands |
| 74 | + # --zone arg # The name of the local zone |
| 75 | + # --master_host arg # The name of the master host for auto-signing the csr; |
| 76 | + # # syntax: host[,port] |
| 77 | + # --endpoint arg # Connect to remote endpoint; syntax: cn[,host,port] |
| 78 | + # --listen arg # Listen on host,port |
| 79 | + # --ticket arg # Generated ticket number for this request |
| 80 | + # --trustedcert arg # Trusted master certificate file |
| 81 | + # --cn arg # The certificate's common name |
| 82 | + # --accept-config # Accept config from master |
| 83 | + # --accept-commands # Accept commands from master |
| 84 | + # --master # Use setup for a master instance |
| 85 | + - name: Restart Icinga |
| 86 | + service: |
| 87 | + name: icinga2 |
| 88 | + state: reloaded |
| 89 | + |
| 90 | + - name: Restart Icinga master |
| 91 | + service: |
| 92 | + name: icinga2 |
| 93 | + state: reloaded |
| 94 | + delegate_to: "{{ icinga2_master }}" |
| 95 | + when: not pki_configured |
0 commit comments