Skip to content

In FreeBSD, the module sysctl always reports changed when sysctl_file is not /etc/sysctl.conf or /etc/sysctl.conf.local #663

@vbotka

Description

@vbotka
SUMMARY

In FreeBSD, this module can reload only /etc/sysctl.conf and /etc/sysctl.conf.local

    def reload_sysctl(self):                                                                                         
        if self.platform == 'freebsd':                                                                               
            # freebsd doesn't support -p, so reload the sysctl service                                               
            rc, out, err = self.module.run_command('/etc/rc.d/sysctl reload', environ_update=self.LANG_ENV)

(The problem is also in OpenBSD.)

shell> /etc/rc.d/sysctl rcvar
# sysctl : Set sysctl variables from /etc/sysctl.conf and /etc/sysctl.conf.local

The default option is reload=True. As a result, /etc/sysctl.conf and /etc/sysctl.conf.local are reloaded even when the option is, for example, sysctl_file=/boot/loader.conf. As a result, _values_is_equal is always False, because proc_value is not updated in the system

        # use the sysctl command or not?                                                                             
        if self.args['sysctl_set'] and self.args['state'] == "present":                                              
            if self.proc_value is None:                                                                              
                self.changed = True                                                                                  
            elif not self._values_is_equal(self.proc_value, self.args['value']):                                     
                self.changed = True                                                                                  
                self.set_proc = True

        # Do the work                                                                                                
        if not self.module.check_mode:                                                                               
            if self.set_proc:                                                                                        
                self.set_token_value(self.args['name'], self.args['value'])                                          
            if self.write_file:                                                                                      
                self.write_sysctl()                                                                                  
            if self.changed and self.args['reload']:                                                                 
                self.reload_sysctl()
ISSUE TYPE
  • Bug Report
COMPONENT NAME

sysctl

ANSIBLE VERSION
ansible [core 2.18.6]
  config file = /home/vlado/.ansible.cfg
  configured module search path = ['/home/vlado/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vlado/env/lib/python3.12/site-packages/ansible
  ansible collection location = /home/vlado/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vlado/env/bin/ansible
  python version = 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] (/home/vlado/env/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
# /home/vlado/env/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
ansible.posix 1.6.2 
CONFIGURATION
ANSIBLE_PIPELINING(/export/scratch/sandbox/tmp1/test-176/ansible.cfg) = True
CONFIG_FILE() = /export/scratch/sandbox/tmp1/test-176/ansible.cfg
DEFAULT_HOST_LIST(/export/scratch/sandbox/tmp1/test-176/ansible.cfg) = ['/scratch/sandbox/tmp1/test-176/hosts']
RETRY_FILES_ENABLED(/export/scratch/sandbox/tmp1/test-176/ansible.cfg) = False

GALAXY_SERVERS:
OS / ENVIRONMENT
shell> uname -a
FreeBSD srv.example.org 14.3-RELEASE FreeBSD 14.3-RELEASE releng/14.3-n271432-8c9ce319fef7 GENERIC amd64
STEPS TO REPRODUCE
    - name: Update loader.conf
      ansible.posix.sysctl:
        sysctl_file: /boot/loader.conf
        name: security.jail.param.jid
        value: '"1"'

Notes:

  • Quoting man loader.conf:
     All settings have the following format:

           variable="value"
  • Read only tunables.
shell> sysctl security.jail.param.jid=1
sysctl: oid 'security.jail.param.jid' is a read only tunable
sysctl: Tunable values are set in /boot/loader.conf

shell> echo $?
1
EXPECTED RESULTS

The task is idempotent

TASK [Update loader.conf] *******************************************************************************************
ok: [srv]
ACTUAL RESULTS

The task is not idempotent

TASK [Update loader.conf] *******************************************************************************************
changed: [srv]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions