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

interfaces_file - fixed dup options bug (#3862)

* interfaces_file - fixed dup options bug

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-12-08 09:54:54 +13:00 committed by GitHub
parent fb79c2998e
commit 3dd5b0d343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- interfaces_file - fixed the check for existing option in interface (https://github.com/ansible-collections/community.general/issues/3841).

View file

@ -253,7 +253,7 @@ def set_interface_option(module, lines, iface, option, raw_value, state, address
last_line_dict = iface_lines[-1] last_line_dict = iface_lines[-1]
return add_option_after_line(option, value, iface, lines, last_line_dict, iface_options, address_family) return add_option_after_line(option, value, iface, lines, last_line_dict, iface_options, address_family)
if option in ["pre-up", "up", "down", "post-up"] and all(ito for ito in target_options if ito['value'] != value): if option in ["pre-up", "up", "down", "post-up"] and all(ito['value'] != value for ito in target_options):
return add_option_after_line(option, value, iface, lines, target_options[-1], iface_options, address_family) return add_option_after_line(option, value, iface, lines, target_options[-1], iface_options, address_family)
# if more than one option found edit the last one # if more than one option found edit the last one

View file

@ -0,0 +1,7 @@
iface eth0 inet static
address 1.2.3.4
netmask 255.255.255.0
gateway 1.2.3.1
up route add -net 1.2.3.4 netmask 255.255.255.0 gw 1.2.3.1 eth0
up ip addr add 4.3.2.1/32 dev eth0
down ip addr add 4.3.2.1/32 dev eth0

View file

@ -2,6 +2,7 @@
- name: - name:
set_fact: set_fact:
interfaces_testfile: '{{ remote_tmp_dir }}/interfaces' interfaces_testfile: '{{ remote_tmp_dir }}/interfaces'
interfaces_testfile_3841: '{{ remote_tmp_dir }}/interfaces_3841'
- name: Copy interfaces file - name: Copy interfaces file
copy: copy:
@ -31,3 +32,32 @@
- assert: - assert:
that: that:
- ifile_2 is not changed - ifile_2 is not changed
- name: 3841 - copy interfaces file
copy:
src: 'files/interfaces_ff_3841'
dest: '{{ interfaces_testfile_3841 }}'
- name: 3841 - floating_ip_interface_up_ip 2a01:a:b:c::1/64 dev eth0
interfaces_file:
option: up
iface: eth0
dest: "{{ interfaces_testfile_3841 }}"
value: 'ip addr add 2a01:a:b:c::1/64 dev eth0'
state: present
register: ifile_3841_a
- name: 3841 - floating_ip_interface_up_ip 2a01:a:b:c::1/64 dev eth0 (again)
interfaces_file:
option: up
iface: eth0
dest: "{{ interfaces_testfile_3841 }}"
value: 'ip addr add 2a01:a:b:c::1/64 dev eth0'
state: present
register: ifile_3841_b
- name: 3841 - check assertions
assert:
that:
- ifile_3841_a is changed
- ifile_3841_b is not changed