ansible 之 sysctl

sysctl

用途:控制系统中的 /sbin/sysctl 命令

官方文档

[root@ansible ansible]# ansible-doc sysctl
> SYSCTL    (/usr/lib/python2.7/site-packages/ansible-2.8.0.dev0-py2.7.egg/ansible/modules/system/sysctl.py)

        This module manipulates sysctl entries and optionally performs a `/sbin/sysctl -p' after
        changing them.

  * This module is maintained by The Ansible Core Team
OPTIONS (= is mandatory):

- ignoreerrors
        Use this option to ignore errors about unknown keys.
        [Default: no]
        type: bool

= name
        The dot-separated path (aka `key') specifying the sysctl variable.
        (Aliases: key)

- 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.
        [Default: yes]
        type: bool

- 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
        [Default: no]
        type: bool
        version_added: 1.5
        

- value
        Desired value of the sysctl key.
        (Aliases: val)[Default: (null)]


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

参数解释

  • ignoreerrors
    默认值:no
    类型:bool
    使用此选项将忽略一些不知道的错误 key,即所设置的 name 参数

= name
别名:key
变量名字

  • reload
    默认值:yes
    类型:bool
    当设置为yes时,如果sysctl_file被更新,则执行 /sbin/sysctl -p命令;当设置为 no时,即使 sysctl_file 文件被更新,也不会重载sysctl

  • state
    默认值:present
    选项:presentabsent

  • sysctl_file
    默认值:/etc/sysctl.conf
    指定 sysctl.conf 配置文件的绝对路径,而不是/etc/sysctl.conf

  • sysctl_set
    默认值:no
    类型:bool

  • value
    别名:val
    默认值:null

posted @ 2018-12-07 16:15  McSiberiaWolf  阅读(2114)  评论(0)    收藏  举报