Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible notify: sudo sysctl -p --system

Tags:

ansible

I have a requirement to update /etc/sysct.conf, but then I need to run systemctl -p --system if that is changed.

How can I achieve that in my playbook?

like image 367
Coder1 Avatar asked Oct 28 '25 04:10

Coder1


1 Answers

You could do this either by using a handler or registering the task and execute the reload task conditionally. The below snippet shows how to do this by registering file change

- copy:
    src: sysctl.conf
    dest: /etc/sysctl.conf
    owner: root
    group: root
  register: result

- shell: sysctl -p --system
  become: yes
  when: result.changed
like image 135
tux Avatar answered Oct 30 '25 15:10

tux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!