Compare commits

..

1 commit

Author SHA1 Message Date
Mikhail Emelchenkov
a1ed6813e0
Merge c8d3acb75f into d36a289deb 2024-04-05 23:14:26 +01:00
3 changed files with 2 additions and 39 deletions

View file

@ -1,3 +0,0 @@
---
bugfixes:
- sysctl - fix sysctl to work properly on symlinks (https://github.com/ansible-collections/ansible.posix/issues/111).

View file

@ -366,7 +366,7 @@ class SysctlModule(object):
# Completely rewrite the sysctl file # Completely rewrite the sysctl file
def write_sysctl(self): def write_sysctl(self):
# open a tmp file # open a tmp file
fd, tmp_path = tempfile.mkstemp('.conf', '.ansible_m_sysctl_', os.path.dirname(os.path.realpath(self.sysctl_file))) fd, tmp_path = tempfile.mkstemp('.conf', '.ansible_m_sysctl_', os.path.dirname(self.sysctl_file))
f = open(tmp_path, "w") f = open(tmp_path, "w")
try: try:
for l in self.fixed_lines: for l in self.fixed_lines:
@ -377,7 +377,7 @@ class SysctlModule(object):
f.close() f.close()
# replace the real one # replace the real one
self.module.atomic_move(tmp_path, os.path.realpath(self.sysctl_file)) self.module.atomic_move(tmp_path, self.sysctl_file)
# ============================================================== # ==============================================================

View file

@ -332,37 +332,3 @@
that: that:
- sysctl_invalid_set1 is failed - sysctl_invalid_set1 is failed
- "'vm.mmap_rnd_bits' not in sysctl_invalid_conf_content.stdout" - "'vm.mmap_rnd_bits' not in sysctl_invalid_conf_content.stdout"
# Test sysctl: sysctl_file is symlink
- name: Create link source
ansible.builtin.copy:
content: |
# Testing Ansible Sysctl module on symlink.
dest: /tmp/ansible_sysctl_test.conf
mode: "0644"
- name: Create symlink to the conf file
ansible.builtin.file:
src: /tmp/ansible_sysctl_test.conf
dest: /tmp/ansible_sysctl_test_symlink.conf
state: link
- name: Use sysctl module with symlink sysctl file
ansible.posix.sysctl:
name: 'kernel.randomize_va_space'
value: '1'
sysctl_file: /tmp/ansible_sysctl_test_symlink.conf
state: present
sysctl_set: false
reload: false
- name: Stat sysctl file
ansible.builtin.stat:
path: /tmp/ansible_sysctl_test_symlink.conf
register: stat_result
- name: Ensure the sysctl file remains a symlink
ansible.builtin.assert:
that:
- stat_result.stat.islnk is defined and stat_result.stat.islnk
- stat_result.stat.lnk_source == '/tmp/ansible_sysctl_test.conf'