|
| 1 | +--- |
| 2 | +# expects to be called with variable pve_ldap_realm set |
| 3 | + |
| 4 | +- name: Get pre-sync state of groups |
| 5 | + ansible.builtin.shell: pveum group list --output-format json-pretty |
| 6 | + register: groups_before |
| 7 | + changed_when: false |
| 8 | + |
| 9 | +- name: Get pre-sync state of users |
| 10 | + ansible.builtin.shell: pveum user list --output-format json-pretty |
| 11 | + register: users_before |
| 12 | + changed_when: false |
| 13 | + |
| 14 | +- name: "Sync ldap-based realm {{ pve_ldap_realm.name }}" |
| 15 | + ansible.builtin.shell: | |
| 16 | + pveum realm sync {{ pve_ldap_realm.name }} |
| 17 | + changed_when: false |
| 18 | + |
| 19 | +- name: Get post-sync state of groups |
| 20 | + ansible.builtin.shell: pveum group list --output-format json-pretty |
| 21 | + register: groups_after |
| 22 | + changed_when: false |
| 23 | + |
| 24 | +- name: Get post-sync state of users |
| 25 | + ansible.builtin.shell: pveum user list --output-format json-pretty |
| 26 | + register: users_after |
| 27 | + changed_when: false |
| 28 | + |
| 29 | +- name: Create temporary file for pre-post-sync comparation |
| 30 | + ansible.builtin.tempfile: |
| 31 | + state: file |
| 32 | + suffix: pve_realm_sync_pre |
| 33 | + register: pre_sync_content |
| 34 | + changed_when: false |
| 35 | + |
| 36 | +- name: Save pre-sync state of groups and users |
| 37 | + ansible.builtin.copy: |
| 38 | + content: | |
| 39 | + {{ groups_before.stdout | from_json | sort(attribute='groupid') | to_yaml }} |
| 40 | + {{ users_before.stdout | from_json | sort(attribute='userid') | to_yaml }} |
| 41 | + dest: "{{ pre_sync_content.path }}" |
| 42 | + changed_when: false |
| 43 | + when: not ansible_check_mode |
| 44 | + |
| 45 | +- name: "Compare to post-sync state of groups and users for realm {{ pve_ldap_realm.name }}" |
| 46 | + ansible.builtin.copy: |
| 47 | + content: | |
| 48 | + {{ groups_after.stdout | from_json | sort(attribute='groupid') | to_yaml }} |
| 49 | + {{ users_after.stdout | from_json | sort(attribute='userid') | to_yaml }} |
| 50 | + dest: "{{ pre_sync_content.path }}" |
| 51 | + when: not ansible_check_mode |
| 52 | + diff: true |
| 53 | + |
| 54 | +- name: Remove the temporary file for pre-post-sync comparation |
| 55 | + ansible.builtin.file: |
| 56 | + path: "{{ pre_sync_content.path }}" |
| 57 | + state: absent |
| 58 | + when: not ansible_check_mode |
| 59 | + changed_when: false |
0 commit comments