How to disable SELinux on Ubuntu with Ansible?

cloud_cloud picture cloud_cloud · May 30, 2017 · Viewed 7k times · Source

The playbook:

---
- name: Update repositories cache
  apt: update_cache=yes

- name: Install build-essential
  apt: name=build-essential state=present

- name: Disable SELinux
  selinux: state=disabled

The result:

TASK [common : Update repositories cache] ***************************************************************************************************************************************************************************************************
changed: [server]

TASK [common : Install build-essential] *****************************************************************************************************************************************************************************************************
ok: [server]

TASK [common : Disable SELinux] *************************************************************************************************************************************************************************************************************
fatal: [server]: FAILED! => {"changed": false, "failed": true, "msg": "libselinux-python required for this module"}

I tried to find libselinux-python but it seems like not exist. When I try some other libraries such as python-selinux, can't been installed on the system.

Answer

Sahil Gulati picture Sahil Gulati · May 30, 2017

Change you tasks to this. You need to install python-selinux first. Ansible intro install requirements

You should add this to your tasks.

- name: Install the libselinux-python package
  apt: name=python-selinux state=present

Whole tasks will be like this.

---
- name: Update repositories cache
  apt: update_cache=yes

- name: Install build-essential
  apt: name=build-essential state=present

- name: Install the libselinux-python package
  apt: name=python-selinux state=present

- name: Disable SELinux
  selinux: state=disabled