Just getting my head around Ansible. Just trying to see what I am doing wrong or what is a better way to reach my goal.
Task :
My goal here is to update a file /proc/sys/vm/overcommit_memory
. I want to put the value 0
into it. I also want the value it was before I changed it to be logged and displayed to me in output in case I need to rollback.
The below works fine but wanted to see if there are better ways to do it.
---
- hosts: "{{ target }}"
gather_facts: yes
become: yes
tasks:
- name: "update overcommit value on {{ target }} ..."
shell: |
echo "the value was "
cat /proc/sys/vm/overcommit_memory
echo 0 > /proc/sys/vm/overcommit_memory
echo "the value now is "
cat /proc/sys/vm/overcommit_memory
register: rc
become: true
become_user: root
- debug:
var: rc.stdout_lines
Thanks in advance