htpasswd: let changed reflect updated permissions (#9490)

* Let changed reflect updated permissions.

* Make pylint happy.
pull/9503/head
Felix Fontein 2024-12-31 00:19:55 +01:00 committed by GitHub
parent 01244237a1
commit 1e28302a66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,3 @@
bugfixes:
- "htpasswd - report changes when file permissions are adjusted
(https://github.com/ansible-collections/community.general/issues/9485, https://github.com/ansible-collections/community.general/pull/9490)."

View File

@ -243,8 +243,9 @@ def main():
(msg, changed) = absent(path, username, check_mode)
else:
module.fail_json(msg="Invalid state: %s" % state)
return # needed to make pylint happy
check_file_attrs(module, changed, msg)
(msg, changed) = check_file_attrs(module, changed, msg)
module.exit_json(msg=msg, changed=changed)
except Exception as e:
module.fail_json(msg=to_native(e))

View File

@ -13,6 +13,7 @@
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0644"
check_mode: true
register: add_bob_check
@ -21,6 +22,7 @@
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0644"
register: add_bob
- name: add bob (idempotency)
@ -28,13 +30,40 @@
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0644"
register: add_bob_idempot
- name: update permissions (check mode)
community.general.htpasswd:
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0600"
check_mode: true
register: update_perms_check
- name: update permissions
community.general.htpasswd:
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0600"
register: update_perms
- name: update permissions (idempotency)
community.general.htpasswd:
path: "{{ htpasswd_path }}"
name: bob
password: c00lbob
mode: "0600"
register: update_perms_idempot
- name: add bob new password
community.general.htpasswd:
path: "{{ htpasswd_path }}"
name: bob
password: SUPERsecret
mode: "0600"
register: add_bob_newpw
- name: add bob new password (idempotency)
@ -42,6 +71,7 @@
path: "{{ htpasswd_path }}"
name: bob
password: SUPERsecret
mode: "0600"
register: add_bob_newpw_idempot
- name: test add bob assertions
@ -50,6 +80,9 @@
- add_bob_check is changed
- add_bob is changed
- add_bob_idempot is not changed
- update_perms_check is changed
- update_perms is changed
- update_perms_idempot is not changed
- add_bob_newpw is changed
- add_bob_newpw_idempot is not changed
@ -58,6 +91,7 @@
path: "{{ htpasswd_path }}"
name: bob
state: absent
mode: "0600"
check_mode: true
register: del_bob_check
@ -66,6 +100,7 @@
path: "{{ htpasswd_path }}"
name: bob
state: absent
mode: "0600"
register: del_bob
- name: remove bob (idempotency)
@ -73,6 +108,7 @@
path: "{{ htpasswd_path }}"
name: bob
state: absent
mode: "0600"
register: del_bob_idempot
- name: test remove bob assertions