1

I have hit this a few times and never figured it out/ it resolved itself.

Running below playbook gives an error but it does make the change requested. . . .

If I run the same play again it does show the message but that is cause it is not updating the sysctl.

---
- hosts: "{{ target }}"
  gather_facts: yes
  become: yes
  become_user: root

  tasks:
  - name: add a vm.overcommit_memory setting at the end of the sysctl.conf
    sysctl: name=vm.overcommit_memory value=0 state=present reload=yes

The error is:

fatal: [testbox.local]: FAILED! => {"changed": false, "msg": "Failed to reload sysctl: net.ipv4.tcp_syncookies = 1\nnet.ipv4.tcp_synack_retries = 2\nnet.ipv4.conf.all.accept_redirects = 0\nnet.ipv4.conf.default.accept_redirects = 0\nnet.ipv6.conf.all.accept_ra = 0\nnet.ipv6.conf.default.accept_ra = 0\nnet.ipv4.icmp_ignore_bogus_error_responses = 1\nnet.ipv6.conf.all.disable_ipv6 = 1\nnet.ipv6.conf.default.disable_ipv6 = 1\nkernel.randomize_va_space = 0\nvm.swappiness = 5\nvm.overcommit_memory = 0\nkernel.shmmni = 15872\nkernel.shmmax = 67546587136\nkernel.shmall = 32981732\nkernel.sem = 250 256000 32 15872\nkernel.msgmni = 64417\nkernel.msgmax = 65536\nkernel.msgmnb = 65536\nsysctl: setting key \"kernel.msgmni\": Invalid argument\nsysctl: cannot stat /proc/sys/randomize_va_space: No such file or directory\nsysctl: cannot stat /proc/sys/“vm/overcommit_memory”: No such file or directory\n"}
U880D
  • 8,601
  • 6
  • 24
  • 40

2 Answers2

1

According the error message

No such file or directory\nsysctl: cannot stat /proc/sys/“vm/overcommit_memory”: No such file or directory\n"

it seems you are running into a barely documented issue. The file path isn't constructed correctly. For possible reasons you may a look into @blami's answer, since there is also a correct entry in the message with vm.overcommit_memory = 0.

Furthermore may need to use use the YAML notation like

- name: Add a 'vm.overcommit_memory' setting at the end of the 'sysctl.conf'
  sysctl: 
    name: vm.overcommit_memory
    value: 0 
    state: present
    reload: yes

which is also used in linux-system-roles/kernel_settings for vm. settings.

Further Q&A

U880D
  • 8,601
  • 6
  • 24
  • 40
1

There is likely problem with /etc/sysctl.conf prior the change applied by play. If you look at error message there is typo in kernel.msgmni (which should be really kernel.msgmin) and also double quotes around the path to vm.overcommit_memory. From that I suspect there are bad lines in file from previous attempts? Try to comment out these or try again with vanilla file obtained from your distribution.

On reload, good lines are still applied by sysctl; but there are some wrong lines in file which sysctl fails to apply, report and also why it exits with non-zero exit code - which makes play to fail.

blami
  • 6,588
  • 2
  • 23
  • 31