1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #7612/5adb7ab9 backport][stable-7] interfaces_file: filter by address_familiy when updating method (#7615)

interfaces_file: filter by address_familiy when updating method (#7612)

* When updating method, check address_family if provided.

* Also test modifying 'method' without address_family filter.

(cherry picked from commit 5adb7ab948)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2023-11-26 20:30:52 +01:00 committed by GitHub
parent a4739d8a36
commit d789351195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "interface_files - also consider ``address_family`` when changing ``option=method`` (https://github.com/ansible-collections/community.general/issues/7610, https://github.com/ansible-collections/community.general/pull/7612)."

View file

@ -340,6 +340,8 @@ def addOptionAfterLine(option, value, iface, lines, last_line_dict, iface_option
changed = False
for ln in lines:
if ln.get('line_type', '') == 'iface' and ln.get('iface', '') == iface and value != ln.get('params', {}).get('method', ''):
if address_family is not None and ln.get('address_family') != address_family:
continue
changed = True
ln['line'] = re.sub(ln.get('params', {}).get('method', '') + '$', value, ln.get('line'))
ln['params']['method'] = value

View file

@ -7,6 +7,7 @@
set_fact:
interfaces_testfile: '{{ remote_tmp_dir }}/interfaces'
interfaces_testfile_3841: '{{ remote_tmp_dir }}/interfaces_3841'
interfaces_testfile_7610: '{{ remote_tmp_dir }}/interfaces_7610'
- name: Copy interfaces file
copy:
@ -65,3 +66,60 @@
that:
- ifile_3841_a is changed
- ifile_3841_b is not changed
- name: 7610 - create file
copy:
dest: '{{ interfaces_testfile_7610 }}'
content: |
iface ens3 inet dhcp
iface ens3 inet6 auto
- name: 7610 - modify file
interfaces_file:
dest: '{{ interfaces_testfile_7610 }}'
iface: ens3
address_family: "inet6"
option: "{{ item.option }}"
value: "{{ item.value }}"
loop:
- option: "method"
value: "static"
- option: "address"
value: "1:2::3/48"
- name: 7610 - read file
slurp:
src: '{{ interfaces_testfile_7610 }}'
register: content_7610
- name: 7610 - check assertions
assert:
that:
- content_7610.content | b64decode == expected_content
vars:
expected_content: |
iface ens3 inet dhcp
iface ens3 inet6 static
address 1:2::3/48
- name: 7610 - modify file again
interfaces_file:
dest: '{{ interfaces_testfile_7610 }}'
iface: ens3
option: method
value: foobar
- name: 7610 - read file
slurp:
src: '{{ interfaces_testfile_7610 }}'
register: content_7610
- name: 7610 - check assertions
assert:
that:
- content_7610.content | b64decode == expected_content
vars:
expected_content: |
iface ens3 inet foobar
iface ens3 inet6 foobar
address 1:2::3/48