mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* sudoers: fix handling of state: absent (#4852)
* typo fixes
(cherry picked from commit 44e21dd407
)
Co-authored-by: s-hamann <10639154+s-hamann@users.noreply.github.com>
This commit is contained in:
parent
48fbd69835
commit
f8650f8d85
3 changed files with 22 additions and 3 deletions
2
changelogs/fragments/4852-sudoers-state-absent.yml
Normal file
2
changelogs/fragments/4852-sudoers-state-absent.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "sudoers - fix incorrect handling of ``state: absent`` (https://github.com/ansible-collections/community.general/issues/4852)."
|
|
@ -168,9 +168,12 @@ class Sudoers(object):
|
||||||
return "{owner} ALL={runas}{nopasswd} {commands}\n".format(owner=owner, runas=runas_str, nopasswd=nopasswd_str, commands=commands_str)
|
return "{owner} ALL={runas}{nopasswd} {commands}\n".format(owner=owner, runas=runas_str, nopasswd=nopasswd_str, commands=commands_str)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.state == 'absent' and self.exists():
|
if self.state == 'absent':
|
||||||
self.delete()
|
if self.exists():
|
||||||
return True
|
self.delete()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
if self.exists() and self.matches():
|
if self.exists() and self.matches():
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -135,6 +135,18 @@
|
||||||
register: revoke_rule_1_stat
|
register: revoke_rule_1_stat
|
||||||
|
|
||||||
|
|
||||||
|
- name: Revoke non-existing rule
|
||||||
|
community.general.sudoers:
|
||||||
|
name: non-existing-rule
|
||||||
|
state: absent
|
||||||
|
register: revoke_non_existing_rule
|
||||||
|
|
||||||
|
- name: Stat non-existing rule
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ sudoers_path }}/non-existing-rule"
|
||||||
|
register: revoke_non_existing_rule_stat
|
||||||
|
|
||||||
|
|
||||||
# Run assertions
|
# Run assertions
|
||||||
|
|
||||||
- name: Check rule 1 file stat
|
- name: Check rule 1 file stat
|
||||||
|
@ -151,6 +163,7 @@
|
||||||
- rule_1_again is not changed
|
- rule_1_again is not changed
|
||||||
- rule_5 is changed
|
- rule_5 is changed
|
||||||
- revoke_rule_1 is changed
|
- revoke_rule_1 is changed
|
||||||
|
- revoke_non_existing_rule is not changed
|
||||||
|
|
||||||
- name: Check contents
|
- name: Check contents
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
|
@ -166,3 +179,4 @@
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- not revoke_rule_1_stat.stat.exists
|
- not revoke_rule_1_stat.stat.exists
|
||||||
|
- not revoke_non_existing_rule_stat.stat.exists
|
||||||
|
|
Loading…
Reference in a new issue