mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 15:15:26 +01:00
Merge pull request #55 from maxamillion/issues/37/authorized_key-check_mode-inconsistent-return
authorized_keys - consistent behavior in check_mode Reviewed-by: https://github.com/apps/ansible-zuul
This commit is contained in:
commit
916b96b4d9
3 changed files with 18 additions and 10 deletions
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
bugfixes:
|
||||
- authorized_keys - fix inconsistent return value for check mode (https://github.com/ansible-collections/ansible.posix/issues/37)
|
||||
|
|
@ -635,13 +635,9 @@ def enforce_state(module, params):
|
|||
}
|
||||
params['diff'] = diff
|
||||
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True, diff=diff)
|
||||
if not module.check_mode:
|
||||
writefile(module, filename, new_content)
|
||||
params['changed'] = True
|
||||
else:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=False)
|
||||
|
||||
return params
|
||||
|
||||
|
|
|
|||
|
|
@ -410,12 +410,13 @@
|
|||
# -------------------------------------------------------------
|
||||
# check mode
|
||||
|
||||
- name: copy an existing file in place with comments
|
||||
- name: CHECK MODE | copy an existing file in place with comments
|
||||
copy:
|
||||
src: existing_authorized_keys
|
||||
dest: "{{ output_dir | expanduser }}/authorized_keys"
|
||||
|
||||
- authorized_key:
|
||||
- name: CHECK MODE | add key in check mode to validate return codes
|
||||
authorized_key:
|
||||
user: root
|
||||
key: "{{ multiple_key_different_order_2 }}"
|
||||
state: present
|
||||
|
|
@ -423,13 +424,21 @@
|
|||
check_mode: True
|
||||
register: result
|
||||
|
||||
- name: assert that the file was not changed
|
||||
- name: CHECK MODE | assert that authorized_keys return values are consistent
|
||||
assert:
|
||||
that:
|
||||
- 'result.changed == True'
|
||||
- '"user" in result'
|
||||
- '"key" in result'
|
||||
|
||||
- name: CHECK MODE | recopy authorized_keys to ensure it was not changed
|
||||
copy:
|
||||
src: existing_authorized_keys
|
||||
dest: "{{ output_dir | expanduser }}/authorized_keys"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: CHECK MODE | assert that the authorized_keys file was not changed
|
||||
assert:
|
||||
that:
|
||||
- 'result.changed == False'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue