From 55ea4ba1de74aceb8c33f5aec128c34aeb215caf Mon Sep 17 00:00:00 2001 From: satken2 Date: Fri, 11 Jun 2021 23:57:09 +0900 Subject: [PATCH] sysctl: Fixed sysctl to work on symlinks(#111) --- .../206_fix_sysctl_to_work_on_symlinks.yml | 3 ++ .../integration/targets/sysctl/tasks/main.yml | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 changelogs/fragments/206_fix_sysctl_to_work_on_symlinks.yml diff --git a/changelogs/fragments/206_fix_sysctl_to_work_on_symlinks.yml b/changelogs/fragments/206_fix_sysctl_to_work_on_symlinks.yml new file mode 100644 index 0000000000..703a6a2e6d --- /dev/null +++ b/changelogs/fragments/206_fix_sysctl_to_work_on_symlinks.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- sysctl - fix sysctl to work properly on symlinks (https://github.com/ansible-collections/ansible.posix/issues/111). diff --git a/tests/integration/targets/sysctl/tasks/main.yml b/tests/integration/targets/sysctl/tasks/main.yml index 249bde1cb3..db9278890e 100644 --- a/tests/integration/targets/sysctl/tasks/main.yml +++ b/tests/integration/targets/sysctl/tasks/main.yml @@ -332,3 +332,36 @@ that: - sysctl_invalid_set1 is failed - "'vm.mmap_rnd_bits' not in sysctl_invalid_conf_content.stdout" + + # Test sysctl: sysctl_file is symlink + - name: Create link source + copy: + content: | + # Testing Ansible Sysctl module on symlink. + dest: /tmp/ansible_sysctl_test.conf + + - name: Create symlink to the conf file + file: + src: /tmp/ansible_sysctl_test.conf + dest: /tmp/ansible_sysctl_test_symlink.conf + state: link + + - name: Use sysctl module with symlink sysctl file + sysctl: + name: 'kernel.randomize_va_space' + value: '1' + sysctl_file: /tmp/ansible_sysctl_test_symlink.conf + state: present + sysctl_set: false + reload: false + + - Stat sysctl file + stat: + path: /tmp/ansible_sysctl_test_symlink.conf + register: stat_result + + - Ensure the sysctl file remains a symlink + assert: + that: + - stat_result.stat.islnk is defined and stat_result.stat.islnk + - stat_result.stat.lnk_source == /tmp/ansible_sysctl_test.conf