mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
[stable-10] sysrc: Use shlex (#10400)
* Fix #10394 Use configparser. * Fix #10394 configparser is in Python3 only. * Fix #10394 return condition. * Fix #10394 Use ConfigParser with Python2. * Fix #10394 import configparser from ansible.module_utils.six.moves * Add changelog fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Fix #10394 use shlex instead of configparser. * Update fragment. * Update changelogs/fragments/10400-sysrc.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/sysrc.py Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Copy tests from #10417. --------- Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
36978d71e1
commit
0be6e61b31
4 changed files with 68 additions and 4 deletions
7
tests/integration/targets/sysrc/files/10394.conf
Normal file
7
tests/integration/targets/sysrc/files/10394.conf
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
k1="v1"
|
||||
jail_list="
|
||||
foo
|
||||
bar"
|
|
@ -369,14 +369,67 @@
|
|||
- "value_2 == sysrc_equals_sign_2.value"
|
||||
- "value_2 == conf.spamd_flags"
|
||||
|
||||
##
|
||||
## sysrc - #10004 state=absent when using default settings will report `changed=true`
|
||||
##
|
||||
- name: Test that a key from /etc/defaults/rc.conf is not used to mark changed
|
||||
sysrc:
|
||||
name: dumpdev
|
||||
state: absent
|
||||
path: /tmp/10004.conf
|
||||
register: sysrc_10004_absent
|
||||
|
||||
- name: Ensure that the defaults are not consulted
|
||||
assert:
|
||||
that:
|
||||
- not sysrc_10004_absent.changed
|
||||
|
||||
- name: Test that a delimited key from /etc/defaults/rc.conf is not used to mark changed
|
||||
sysrc:
|
||||
name: rc_conf_files
|
||||
state: value_absent
|
||||
path: /tmp/10004.conf
|
||||
register: sysrc_10004_value_absent
|
||||
|
||||
- name: Ensure that the default is not consulted
|
||||
assert:
|
||||
that:
|
||||
- not sysrc_10004_value_absent.changed
|
||||
|
||||
##
|
||||
## sysrc - #10394 Ensure that files with multi-line values work
|
||||
##
|
||||
- name: Copy 10394.conf
|
||||
copy:
|
||||
src: 10394.conf
|
||||
dest: /tmp/10394.conf
|
||||
|
||||
- name: Change value for k1
|
||||
sysrc:
|
||||
name: k1
|
||||
value: v2
|
||||
path: /tmp/10394.conf
|
||||
register: sysrc_10394_changed
|
||||
|
||||
- name: Get file content
|
||||
shell: "cat /tmp/10394.conf"
|
||||
register: sysrc_10394_content
|
||||
|
||||
- name: Ensure sysrc changed k1 from v1 to v2
|
||||
assert:
|
||||
that:
|
||||
- sysrc_10394_changed.changed
|
||||
- >
|
||||
'k1="v2"' in sysrc_10394_content.stdout_lines
|
||||
|
||||
always:
|
||||
|
||||
- name: Restore /etc/rc.conf
|
||||
copy:
|
||||
content: "{{ cached_etc_rcconf_content }}"
|
||||
content: "{{ cached_etc_rcconf_content.stdout }}"
|
||||
dest: /etc/rc.conf
|
||||
|
||||
- name: Restore /boot/loader.conf
|
||||
copy:
|
||||
content: "{{ cached_boot_loaderconf_content }}"
|
||||
content: "{{ cached_boot_loaderconf_content.stdout }}"
|
||||
dest: /boot/loader.conf
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue