當我們需要修改內(nèi)核參數(shù)時卵迂,可以使用sysctl 模塊。sysctl 可以對值進行設置绒净,如果需要查詢可以使用shell 模塊见咒。
- name:變量名
- value:值
- reload:文件被更新時,是否使用
sysctl -p
reload 文件 - state:是在文件中 移除(absent)或者設置(present)
- sysctl_file:如果不是默認文件挂疆,指定其他文件
- sysctl_set:使用sysctl 命令設置改览,不一定需要reload 文件
linux sysctl usage
Usage:
sysctl [options] [variable[=value] ...]
Options:
-a, --all display all variables
-A alias of -a
-X alias of -a
--deprecated include deprecated parameters to listing
-b, --binary print value without new line
-e, --ignore ignore unknown variables errors
-N, --names print variable names without values
-n, --values print only values of a variables
-p, --load[=<file>] read values from file
-f alias of -p
--system read values from all system directories
-r, --pattern <expression>
select setting that match expression
-q, --quiet do not echo variable set
-w, --write enable writing a value to variable
-o does nothing
-x does nothing
-d alias of -h
-h, --help display this help and exit
-V, --version output version information and exit
For more details see sysctl(8).
ansible-doc sysctl 文檔
> SYSCTL (/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.py)
This module manipulates sysctl entries and optionally performs a `/sbin/sysctl -p' after changing them.
OPTIONS (= is mandatory):
- ignoreerrors
Use this option to ignore errors about unknown keys.
(Choices: yes, no)[Default: False]
= name
The dot-separated path (aka `key') specifying the sysctl variable.
(Aliases: key)[Default: None]
- reload
If `yes', performs a `/sbin/sysctl -p' if the `sysctl_file' is updated. If `no', does not reload `sysctl' even if the
`sysctl_file' is updated.
(Choices: yes, no)[Default: yes]
- state
Whether the entry should be present or absent in the sysctl file.
(Choices: present, absent)[Default: present]
- sysctl_file
Specifies the absolute path to `sysctl.conf', if not `/etc/sysctl.conf'.
[Default: /etc/sysctl.conf]
- sysctl_set
Verify token value with the sysctl command and set with -w if necessary
(Choices: yes, no)[Default: False]
version_added: 1.5
- value
Desired value of the sysctl key.
(Aliases: val)[Default: None]
AUTHOR: David CHANIAL (@davixx) <david.chanial@gmail.com>
METADATA:
status:
- stableinterface
supported_by: core
示例
EXAMPLES:
# Set vm.swappiness to 5 in /etc/sysctl.conf
- sysctl:
name: vm.swappiness
value: 5
state: present
# Remove kernel.panic entry from /etc/sysctl.conf
- sysctl:
name: kernel.panic
state: absent
sysctl_file: /etc/sysctl.conf
# Set kernel.panic to 3 in /tmp/test_sysctl.conf
- sysctl:
name: kernel.panic
value: 3
sysctl_file: /tmp/test_sysctl.conf
reload: no
# Set ip forwarding on in /proc and do not reload the sysctl file
- sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
# Set ip forwarding on in /proc and in the sysctl file and reload if necessary
- sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
state: present
reload: yes