ansible lineinfile 关闭selinux
时间: 2023-07-21 20:12:44 浏览: 32
可以使用以下Ansible模块来关闭SELinux并将其设置为永久性禁用:
```
- name: Disable SELinux
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: 'SELINUX=disabled'
become: true
become_method: sudo
notify:
- Reboot Server
```
这个任务会查找 `/etc/selinux/config` 文件中以 `SELINUX=` 开头的行,如果找到了,就将其替换为 `SELINUX=disabled`,以达到关闭 SELinux 的目的。注意,这里使用了 `become` 和 `become_method` 来提升为超级用户权限进行操作。
最后,使用 `notify` 关键字通知重启服务器,以使更改生效。
相关问题
ansible使用selinux模块关闭selinux
可以使用 `ansible.builtin.selinux` 模块来关闭SELinux并将其设置为临时禁用:
```
- name: Disable SELinux
ansible.builtin.selinux:
policy: targeted
state: disabled
become: true
become_method: sudo
```
这个任务使用 `ansible.builtin.selinux` 模块将 `policy` 参数设置为 `targeted`,将 `state` 参数设置为 `disabled`,以实现禁用 SELinux 的目的。
注意,这里使用了 `become` 和 `become_method` 来提升为超级用户权限进行操作。
ansible 关闭selinux
可以使用以下Ansible playbook任务来关闭SELinux并将其设置为临时禁用:
```
- name: Disable SELinux
ansible.builtin.seboolean:
name: selinuxuser_execmod
state: no
persistent: yes
become: true
become_method: sudo
```
这个任务使用 `ansible.builtin.seboolean` 模块将 `selinuxuser_execmod` 参数设置为 `no`,以实现禁用 SELinux 的目的。`persistent` 参数设置为 `yes`,以使更改在重启后仍然保持有效。
注意,这里使用了 `become` 和 `become_method` 来提升为超级用户权限进行操作。
相关推荐















