ansible.posix.sysctl (1.5.4) — module

Manage entries in sysctl.conf.

| "added in version" 1.0.0 of ansible.posix"

Authors: David CHANIAL (@davixx)

Install collection

Install with ansible-galaxy collection install ansible.posix:==1.5.4


Add to requirements.yml

  collections:
    - name: ansible.posix
      version: 1.5.4

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Set vm.swappiness to 5 in /etc/sysctl.conf
- ansible.posix.sysctl:
    name: vm.swappiness
    value: '5'
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Remove kernel.panic entry from /etc/sysctl.conf
- ansible.posix.sysctl:
    name: kernel.panic
    state: absent
    sysctl_file: /etc/sysctl.conf
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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

Inputs

    
name:
    aliases:
    - key
    description:
    - The dot-separated path (also known as I(key)) specifying the sysctl variable.
    required: true
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Whether the entry should be present or absent in the sysctl file.
    type: str

value:
    aliases:
    - val
    description:
    - Desired value of the sysctl key.
    type: str

reload:
    default: true
    description:
    - If C(true), performs a I(/sbin/sysctl -p) if the C(sysctl_file) is updated. If C(false),
      does not reload I(sysctl) even if the C(sysctl_file) is updated.
    type: bool

sysctl_set:
    default: false
    description:
    - Verify token value with the sysctl command and set with -w if necessary.
    type: bool

sysctl_file:
    default: /etc/sysctl.conf
    description:
    - Specifies the absolute path to C(sysctl.conf), if not C(/etc/sysctl.conf).
    type: path

ignoreerrors:
    default: false
    description:
    - Use this option to ignore errors about unknown keys.
    type: bool