如何用Ansible在Ubuntu上禁用Selinux



剧本:

---
- name: Update repositories cache
  apt: update_cache=yes
- name: Install build-essential
  apt: name=build-essential state=present
- name: Disable SELinux
  selinux: state=disabled

结果:

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"}

我试图找到libselinux-python,但似乎不存在。当我尝试其他一些库(例如python-selinux(时,无法在系统上安装。

将任务更改为此。您需要先安装python-selinux Ansible intro install requirements

您应该将其添加到您的任务中。

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

整个任务就是这样。

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