[PR #9490/1e28302a backport][stable-9] htpasswd: let changed reflect updated permissions (#9492)

htpasswd: let changed reflect updated permissions (#9490)

* Let changed reflect updated permissions.

* Make pylint happy.

(cherry picked from commit 1e28302a66)

Co-authored-by: Felix Fontein <felix@fontein.de>
pull/9501/head
patchback[bot] 2024-12-31 10:28:53 +01:00 committed by GitHub
parent ae8015667c
commit c7773afebf
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) (msg, changed) = absent(path, username, check_mode)
else: else:
module.fail_json(msg="Invalid state: %s" % state) 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) module.exit_json(msg=msg, changed=changed)
except Exception as e: except Exception as e:
module.fail_json(msg=to_native(e)) module.fail_json(msg=to_native(e))

View File

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