|
| 1 | +--- |
| 2 | +- name: Check domains.cfg exists |
| 3 | + stat: |
| 4 | + path: "/etc/pve/domains.cfg" |
| 5 | + register: _domains_cfg |
| 6 | + |
| 7 | +- name: Create domains.cfg if it does not exist |
| 8 | + file: |
| 9 | + path: "/etc/pve/domains.cfg" |
| 10 | + state: "touch" |
| 11 | + when: |
| 12 | + - not _domains_cfg.stat.exists |
| 13 | + |
| 14 | +- name: Configure domains.cfg |
| 15 | + # The parser for domains.cfg requires a blank line after each domain, |
| 16 | + # and there's a TAB character before printing each key / value pair for a domain |
| 17 | + copy: |
| 18 | + dest: "/etc/pve/domains.cfg" |
| 19 | + owner: "root" |
| 20 | + group: "www-data" |
| 21 | + mode: "0640" |
| 22 | + content: | |
| 23 | + {% for domain in pve_domains_cfg %} |
| 24 | + {{ domain.type }}: {{ domain.name }} |
| 25 | + {% if domain.attributes %} |
| 26 | + {% for k,v in domain.attributes.items() %} |
| 27 | + {% if k != 'bind_password' %} |
| 28 | + {{ k }} {{ v }} |
| 29 | + {% endif %} |
| 30 | + {% endfor %} |
| 31 | + {% endif %} |
| 32 | +
|
| 33 | + {% endfor %} |
| 34 | +
|
| 35 | +- name: Select ldap-based realms with bind_password |
| 36 | + set_fact: |
| 37 | + pve_ldap_realms_with_bind_pw: | |
| 38 | + {{ pve_domains_cfg | selectattr('type', 'in', ['ad', 'ldap']) |
| 39 | + | selectattr('attributes.bind_password', 'defined') }} |
| 40 | +
|
| 41 | +- name: Ensure /etc/pve/priv/realm/ exists |
| 42 | + ansible.builtin.file: |
| 43 | + path: /etc/pve/priv/realm |
| 44 | + state: directory |
| 45 | + owner: root |
| 46 | + group: www-data |
| 47 | + mode: 0700 |
| 48 | + when: pve_ldap_realms_with_bind_pw | length |
| 49 | + |
| 50 | +- name: Ensure ldap-based realm secret files exists |
| 51 | + ansible.builtin.file: |
| 52 | + path: "/etc/pve/priv/realm/{{ item.name }}.pw" |
| 53 | + access_time: preserve |
| 54 | + modification_time: preserve |
| 55 | + state: touch |
| 56 | + mode: 0600 |
| 57 | + with_items: |
| 58 | + - "{{ pve_ldap_realms_with_bind_pw }}" |
| 59 | + |
| 60 | +- name: Update ldap-based realm secret files |
| 61 | + ansible.builtin.copy: |
| 62 | + content: "{{ item.attributes.bind_password }}" |
| 63 | + dest: "/etc/pve/priv/realm/{{ item.name }}.pw" |
| 64 | + owner: root |
| 65 | + group: www-data |
| 66 | + mode: 0600 |
| 67 | + with_items: |
| 68 | + - "{{ pve_ldap_realms_with_bind_pw }}" |
0 commit comments