ansible.posix.selinux 模块 – 更改 SELinux 的策略和状态

注意

此模块是 ansible.posix 集合 (版本 1.6.2) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install ansible.posix。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。

要在剧本中使用它,请指定: ansible.posix.selinux

ansible.posix 1.0.0 中的新增功能

概要

  • 配置 SELinux 模式和策略。

  • 使用后可能需要重新启动。

  • Ansible 不会发出此重新启动请求,但会告知您何时需要重新启动。

要求

在执行此模块的主机上需要以下要求。

  • libselinux-python

参数

参数

注释

configfile

别名:conf,file

字符串

SELinux 配置文件的路径(如果非标准)。

默认值: "/etc/selinux/config"

policy

字符串

要使用的 SELinux 策略的名称(例如 targeted),除非 state=disabled

state

字符串 / 必需

SELinux 模式。

选项

  • "disabled"

  • "enforcing"

  • "permissive"

update_kernel_param

布尔值

ansible.posix 1.4.0 中新增

如果设置为 true,则在禁用/启用 SELinux 时也会更新内核启动参数。

目标系统上必须存在 grubby 工具才能使其工作。

选项

  • false ← (默认)

  • true

示例

- name: Enable SELinux
  ansible.posix.selinux:
    policy: targeted
    state: enforcing

- name: Put SELinux in permissive mode, logging actions that would be blocked.
  ansible.posix.selinux:
    policy: targeted
    state: permissive

- name: Disable SELinux
  ansible.posix.selinux:
    state: disabled

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段

描述

configfile

字符串

SELinux 配置文件的路径。

返回:始终

示例: "/etc/selinux/config"

msg

字符串

描述所做更改的消息。

返回:始终

示例: "Config SELinux state changed from 'disabled' to 'permissive'"

policy

字符串

SELinux 策略的名称。

返回:始终

示例: "targeted"

reboot_required

布尔值

更改是否需要重新启动才能生效。

返回:始终

示例: true

state

字符串

SELinux 模式。

返回:始终

示例: "enforcing"

作者

  • Derek Carter (@goozbach)