| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- when: |
| 7 |
# passlib is dead and doesn't work with recent bcrypt versions anymore |
| 8 |
# (https://foss.heptapod.net/python-libs/passlib/-/work_items/196) |
| 9 |
- ansible_facts.distribution != 'Ubuntu' or ansible_facts.distribution_version is version('26.04', '<') |
| 10 |
block: |
| 11 |
- name: install passlib |
| 12 |
ansible.builtin.pip: |
| 13 |
name: passlib |
| 14 |
notify: remove passlib |
| 15 |
|
| 16 |
- name: add bob (check mode) |
| 17 |
community.general.htpasswd: |
| 18 |
path: "{{ htpasswd_path }}" |
| 19 |
name: bob |
| 20 |
password: c00lbob |
| 21 |
mode: "0644" |
| 22 |
check_mode: true |
| 23 |
register: add_bob_check |
| 24 |
|
| 25 |
- name: add bob |
| 26 |
community.general.htpasswd: |
| 27 |
path: "{{ htpasswd_path }}" |
| 28 |
name: bob |
| 29 |
password: c00lbob |
| 30 |
mode: "0644" |
| 31 |
register: add_bob |
| 32 |
|
| 33 |
- name: add bob (idempotency) |
| 34 |
community.general.htpasswd: |
| 35 |
path: "{{ htpasswd_path }}" |
| 36 |
name: bob |
| 37 |
password: c00lbob |
| 38 |
mode: "0644" |
| 39 |
register: add_bob_idempot |
| 40 |
|
| 41 |
- name: update permissions (check mode) |
| 42 |
community.general.htpasswd: |
| 43 |
path: "{{ htpasswd_path }}" |
| 44 |
name: bob |
| 45 |
password: c00lbob |
| 46 |
mode: "0600" |
| 47 |
check_mode: true |
| 48 |
register: update_perms_check |
| 49 |
|
| 50 |
- name: update permissions |
| 51 |
community.general.htpasswd: |
| 52 |
path: "{{ htpasswd_path }}" |
| 53 |
name: bob |
| 54 |
password: c00lbob |
| 55 |
mode: "0600" |
| 56 |
register: update_perms |
| 57 |
|
| 58 |
- name: update permissions (idempotency) |
| 59 |
community.general.htpasswd: |
| 60 |
path: "{{ htpasswd_path }}" |
| 61 |
name: bob |
| 62 |
password: c00lbob |
| 63 |
mode: "0600" |
| 64 |
register: update_perms_idempot |
| 65 |
|
| 66 |
- name: add bob new password |
| 67 |
community.general.htpasswd: |
| 68 |
path: "{{ htpasswd_path }}" |
| 69 |
name: bob |
| 70 |
password: SUPERsecret |
| 71 |
mode: "0600" |
| 72 |
register: add_bob_newpw |
| 73 |
|
| 74 |
- name: add bob new password (idempotency) |
| 75 |
community.general.htpasswd: |
| 76 |
path: "{{ htpasswd_path }}" |
| 77 |
name: bob |
| 78 |
password: SUPERsecret |
| 79 |
mode: "0600" |
| 80 |
register: add_bob_newpw_idempot |
| 81 |
|
| 82 |
- name: test add bob assertions |
| 83 |
ansible.builtin.assert: |
| 84 |
that: |
| 85 |
- add_bob_check is changed |
| 86 |
- add_bob is changed |
| 87 |
- add_bob_idempot is not changed |
| 88 |
- update_perms_check is changed |
| 89 |
- update_perms is changed |
| 90 |
- update_perms_idempot is not changed |
| 91 |
- add_bob_newpw is changed |
| 92 |
- add_bob_newpw_idempot is not changed |
| 93 |
|
| 94 |
- name: remove bob (check mode) |
| 95 |
community.general.htpasswd: |
| 96 |
path: "{{ htpasswd_path }}" |
| 97 |
name: bob |
| 98 |
state: absent |
| 99 |
mode: "0600" |
| 100 |
check_mode: true |
| 101 |
register: del_bob_check |
| 102 |
|
| 103 |
- name: remove bob |
| 104 |
community.general.htpasswd: |
| 105 |
path: "{{ htpasswd_path }}" |
| 106 |
name: bob |
| 107 |
state: absent |
| 108 |
mode: "0600" |
| 109 |
register: del_bob |
| 110 |
|
| 111 |
- name: remove bob (idempotency) |
| 112 |
community.general.htpasswd: |
| 113 |
path: "{{ htpasswd_path }}" |
| 114 |
name: bob |
| 115 |
state: absent |
| 116 |
mode: "0600" |
| 117 |
register: del_bob_idempot |
| 118 |
|
| 119 |
- name: test remove bob assertions |
| 120 |
ansible.builtin.assert: |
| 121 |
that: |
| 122 |
- del_bob_check is changed |
| 123 |
- del_bob is changed |
| 124 |
- del_bob_idempot is not changed |