ansible.posix.sysctl module – Manage entries in sysctl.conf.

Note

This module is part of the ansible.posix collection (version 1.5.4).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install ansible.posix.

To use it in a playbook, specify: ansible.posix.sysctl.

New in ansible.posix 1.0.0

Synopsis

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

Parameters

Parameter

Comments

ignoreerrors

boolean

Use this option to ignore errors about unknown keys.

Choices:

  • false ← (default)

  • true

name

aliases: key

string / required

The dot-separated path (also known as key) specifying the sysctl variable.

reload

boolean

If true, performs a /sbin/sysctl -p if the sysctl_file is updated. If false, does not reload sysctl even if the sysctl_file is updated.

Choices:

  • false

  • true ← (default)

state

string

Whether the entry should be present or absent in the sysctl file.

Choices:

  • "present" ← (default)

  • "absent"

sysctl_file

path

Specifies the absolute path to sysctl.conf, if not /etc/sysctl.conf.

Default: "/etc/sysctl.conf"

sysctl_set

boolean

Verify token value with the sysctl command and set with -w if necessary.

Choices:

  • false ← (default)

  • true

value

aliases: val

string

Desired value of the sysctl key.

Examples

# 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

Authors

  • David CHANIAL (@davixx)