ansible.posix/plugins/modules
Petr Lautrbach 0a07bdb358
seboolean: make it work with disabled SELinux (#496)
Sometimes it's necessary to configure SELinux before it's enabled on the
system. There's `ignore_selinux_state` which should allow it. Before
this change `seboolean` module failed on SELinux disabled system even
with `ignore_selinux_state: true` and SELinux policy installed while
`semanage boolean` worked as expected:

    $ ansible -i 192.168.121.153, -m seboolean -a "name=ssh_sysadm_login state=on ignore_selinux_state=true" all
    192.168.121.153 | FAILED! => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": false,
        "msg": "Failed to get list of boolean names"
    }

    $ ssh root@192.168.121.153 semanage boolean -l | grep ssh_sysadm_login
    ssh_sysadm_login               (off  ,  off)  Allow ssh to sysadm login

It's caused by `selinux.security_get_boolean_names()` and
`selinux.security_get_boolean_active(name)` which required SELinux
enabled system.

This change adds a fallback to semanage API which works in SELinux
disabled system when SELinux targeted policy is installed:

    ANSIBLE_LIBRARY=plugins/modules ansible -i 192.168.121.153, -m seboolean -a "name=ssh_sysadm_login state=on persistent=true ignore_selinux_state=true" all
    192.168.121.153 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python3"
        },
        "changed": true,
        "name": "ssh_sysadm_login",
        "persistent": true,
        "state": true
    }

    $ ssh root@192.168.121.153 semanage boolean -l | grep ssh_sysadm_login
    ssh_sysadm_login               (on   ,   on)  Allow ssh to sysadm login

Note that without `persistent=true` this module is effectively NO-OP now.

Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
2024-02-06 09:21:27 -06:00
..
__init__.py Initial commit 2020-03-09 13:15:28 +00:00
acl.py Merge pull request #400 from vladislav-sharapov/fix-doc-boolean-values 2022-12-22 08:00:13 +00:00
at.py Fix boolean values in docs 2022-12-09 00:36:29 +04:00
authorized_key.py Fix boolean values in docs 2022-12-09 00:36:29 +04:00
firewalld.py firewalld: make offline do something 2023-11-29 00:06:36 +00:00
firewalld_info.py Warn only when zones were ignored in firewalld_info (#504) 2024-01-09 16:07:58 -06:00
mount.py mount: edit boot parameters warning condition (#523) 2024-01-09 16:06:26 -06:00
patch.py fix document syntax 2023-02-21 12:06:22 +00:00
rhel_facts.py rhel_facts module must use keyword arguments 2023-03-23 15:52:20 -06:00
rhel_rpm_ostree.py Update documented default value for rhel_rpm_ostree's name parameter to match implementation. 2022-12-13 11:48:39 -05:00
rpm_ostree_upgrade.py fixes based on feedback 2022-11-22 09:03:04 -06:00
seboolean.py seboolean: make it work with disabled SELinux (#496) 2024-02-06 09:21:27 -06:00
selinux.py respawn selinux module when selinux is missing 2023-05-14 05:44:46 +00:00
synchronize.py refactor to comply with current ansible-lint and sanity guidelines 2023-12-06 17:22:59 -06:00
sysctl.py Fix boolean values in docs 2022-12-09 00:36:29 +04:00