Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sudoers module does not handle state: absent properly #4852

Closed
1 task done
s-hamann opened this issue Jun 18, 2022 · 2 comments · Fixed by #4853
Closed
1 task done

sudoers module does not handle state: absent properly #4852

s-hamann opened this issue Jun 18, 2022 · 2 comments · Fixed by #4853
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) system

Comments

@s-hamann
Copy link
Contributor

Summary

The community.general.sudoers module does not handle state: absent properly.
If the file specified by name does not exist, it gets created, with possibly invalid content. As a side effect, commands and user/group is required, although these options do not make a lot of sense with state: absent.
If the file specified by name exists, it is (correctly) deleted. Of course, the next invocation of the play creates it again.

Issue Type

Bug Report

Component Name

sudoers

Ansible Version

$ ansible --version
ansible [core 2.12.5]
  config file = ...
  configured module search path = [...]
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /usr/share/ansible/collections
  executable location = /usr/lib/python-exec/python3.9/ansible
  python version = 3.9.12 (main, Jun 17 2022, 16:04:33) [GCC 11.3.0]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /usr/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

Target OS is Debian 11.

Steps to Reproduce

---
- hosts: all
  gather_facts: false
  tasks:
    - community.general.sudoers:
        name: test
        commands: []
        user: root
        state: absent

    - ansible.builtin.stat:
        path: /etc/sudoers.d/test
      register: _stat_sudoers

    - ansible.builtin.assert:
        that:
          - "not _stat_sudoers.stat.exists"

Note: /etc/sudoers.d/test is assumed not to exist prior to running this play.

Expected Results

The play never fails, i.e. /etc/sudoers.d/test gets deleted/not created.

Actual Results

The assertion fails on every second invocation of the play (starting with the first). The file /etc/sudoers.d/test gets created by the sudoers module.
The assertion passes on every other invocation of the play (starting with the second).

PLAY [all] **********************************************************************************************

TASK [community.general.sudoers] ************************************************************************
changed: [test]

TASK [ansible.builtin.stat] *****************************************************************************
ok: [test]

TASK [ansible.builtin.assert] ***************************************************************************
fatal: [test]: FAILED! => {
    "assertion": "not _stat_sudoers.stat.exists",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

PLAY RECAP **********************************************************************************************
test                       : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

cc @JonEllis @JonEllis0
click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) system labels Jun 18, 2022
felixfontein pushed a commit that referenced this issue Jun 19, 2022
* sudoers: fix handling of state: absent (#4852)

* typo fixes
patchback bot pushed a commit that referenced this issue Jun 19, 2022
* sudoers: fix handling of state: absent (#4852)

* typo fixes

(cherry picked from commit 44e21dd)
patchback bot pushed a commit that referenced this issue Jun 19, 2022
* sudoers: fix handling of state: absent (#4852)

* typo fixes

(cherry picked from commit 44e21dd)
felixfontein pushed a commit that referenced this issue Jun 19, 2022
* sudoers: fix handling of state: absent (#4852)

* typo fixes

(cherry picked from commit 44e21dd)

Co-authored-by: s-hamann <[email protected]>
felixfontein pushed a commit that referenced this issue Jun 19, 2022
* sudoers: fix handling of state: absent (#4852)

* typo fixes

(cherry picked from commit 44e21dd)

Co-authored-by: s-hamann <[email protected]>
bratwurzt pushed a commit to bratwurzt/community.general that referenced this issue Nov 7, 2022
This was referenced Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants