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

Selinux module fails if selinux is not installed #21622

Closed
alop opened this issue Feb 18, 2017 · 5 comments · Fixed by #24437
Closed

Selinux module fails if selinux is not installed #21622

alop opened this issue Feb 18, 2017 · 5 comments · Fixed by #24437
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. module This issue/PR relates to a module. selinux

Comments

@alop
Copy link

alop commented Feb 18, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

selinux module

ANSIBLE VERSION
ansible 2.2.1.0
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION
OS / ENVIRONMENT
SUMMARY

If a task wants to set selinux to permissive, but selinux is not installed (RPMS have been erased, /etc/selinux/config doesn't exist) the module fails because it cannot find the config file. This particular case should be OK, as setting it to permissive is effectively disabling it, and it's already disabled.

STEPS TO REPRODUCE

deploy a CentOS/RHEL vm, delete the selinux rpms, rm -rf /etc/selinux
Then attempt to disable to set selinux to permissive

- selinux:
    state: permissive

# Disable SELinux
- selinux:
    state: disabled

EXPECTED RESULTS

Since selinux is not installed, it should be a noop

ACTUAL RESULTS
```
IOError: [Errno 2] No such file or directory: '/etc/selinux/config'\n",
"module_stdout": "", "msg": "MODULE FAILURE"}
```
@ansibot
Copy link
Contributor

ansibot commented Feb 18, 2017

@ansibot ansibot added affects_2.2 This issue/PR affects Ansible v2.2 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Feb 18, 2017
@alikins alikins added waiting_on_contributor This would be accepted but there are no plans to actively work on it. and removed needs_triage Needs a first human triage before being processed. labels Feb 20, 2017
@ansibot ansibot removed the waiting_on_contributor This would be accepted but there are no plans to actively work on it. label Feb 20, 2017
@yabhinav
Copy link

+1

faced similar issue when selinux is not installed on centOS6

- name: Ensure Selinux Disabled
  selinux: state=disabled 
  when: ansible_os_family == 'RedHat'
  become: True
TASK [role_under_test : Ensure Selinux Disabled] *******************************
task path: /etc/ansible/roles/role_under_test/tasks/main.yml:36
Using module file /root/.virtualenvs/ansible_2.2.0.0/lib/python2.6/site-packages/ansible/modules/core/system/selinux.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355 `" && echo ansible-tmp-1488086499.63-182067330321355="` echo $HOME/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355 `" ) && sleep 0'
<localhost> PUT /tmp/tmppzlwwe TO /root/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355/selinux.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355/ /root/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355/selinux.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355/selinux.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1488086499.63-182067330321355/" > /dev/null 2>&1 && sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_Ik_yPG/ansible_module_selinux.py", line 211, in <module>
    main()
  File "/tmp/ansible_Ik_yPG/ansible_module_selinux.py", line 151, in main
    config_policy         = get_config_policy(configfile)
  File "/tmp/ansible_Ik_yPG/ansible_module_selinux.py", line 78, in get_config_policy
    myfile = open(configfile, "r")
IOError: [Errno 2] No such file or directory: '/etc/selinux/config'
fatal: [localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "selinux"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Ik_yPG/ansible_module_selinux.py\", line 211, in <module>\n    main()\n  File \"/tmp/ansible_Ik_yPG/ansible_module_selinux.py\", line 151, in main\n    config_policy         = get_config_policy(configfile)\n  File \"/tmp/ansible_Ik_yPG/ansible_module_selinux.py\", line 78, in get_config_policy\n    myfile = open(configfile, \"r\")\nIOError: [Errno 2] No such file or directory: '/etc/selinux/config'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE"
}

Akasurde added a commit to Akasurde/ansible that referenced this issue May 11, 2017
* Refactor code
* PEP8 fixes
* Check if /etc/selinux/config file exists before
  proceeding any other operations

Fixes ansible#21622

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@Akasurde
Copy link
Member

Akasurde commented May 24, 2017

resolved_by_pr #24437

gundalow pushed a commit that referenced this issue Jun 28, 2017
* Refactor code
* PEP8 fixes
* Check if /etc/selinux/config file exists before
  proceeding any other operations

Fixes #21622

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@boxrick
Copy link

boxrick commented Sep 26, 2018

This is still very much a problem if SELINUX is missing Ansible 2.6.4

fatal: [centos6]: FAILED! => {"changed": false, "details": "Please install SELinux-policy package, if this package is not installed previously.", "msg": "Unable to find file /etc/selinux/config"

@Akasurde
Copy link
Member

@boxrick Could you please open a new issue with your playbook and environment details ? In that way it will be easy to track your issue rather than posting here. Thanks.

@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. module This issue/PR relates to a module. selinux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants