ansible.posix.sysctl 模块 – 管理 sysctl.conf 中的条目。
注意
此模块是 ansible.posix 集合 (版本 1.6.2) 的一部分。
如果您正在使用 ansible
包,则您可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install ansible.posix
。
要在 playbook 中使用它,请指定: ansible.posix.sysctl
。
ansible.posix 1.0.0 中的新增功能
概要
此模块操作 sysctl 条目,并在更改条目后可选地执行
/sbin/sysctl -p
。
参数
参数 |
注释 |
---|---|
使用此选项忽略关于未知键的错误。 选项
|
|
指定 sysctl 变量的点分隔路径(也称为 |
|
如果 选项
|
|
条目在 sysctl 文件中是否存在。 选项
|
|
指定 默认值: |
|
使用 sysctl 命令验证令牌值,如有必要,使用 选项
|
|
sysctl 键的所需值。 |
示例
# Set vm.swappiness to 5 in /etc/sysctl.conf
- ansible.posix.sysctl:
name: vm.swappiness
value: '5'
state: present
# Remove kernel.panic entry from /etc/sysctl.conf
- ansible.posix.sysctl:
name: kernel.panic
state: absent
sysctl_file: /etc/sysctl.conf
# Set kernel.panic to 3 in /tmp/test_sysctl.conf
- ansible.posix.sysctl:
name: kernel.panic
value: '3'
sysctl_file: /tmp/test_sysctl.conf
reload: false
# Set ip forwarding on in /proc and verify token value with the sysctl command
- ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: '1'
sysctl_set: true
# Set ip forwarding on in /proc and in the sysctl file and reload if necessary
- ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: '1'
sysctl_set: true
state: present
reload: true