1
0
Fork 0
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) (#4853)

* sudoers: fix handling of state: absent (#4852)

* typo fixes
This commit is contained in:
s-hamann 2022-06-19 13:34:24 +00:00 committed by GitHub
parent dcdfc9c413
commit 44e21dd407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "sudoers - fix incorrect handling of ``state: absent`` (https://github.com/ansible-collections/community.general/issues/4852)."

View file

@ -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

View file

@ -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