mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Search all assigned ipv6 addresses instead of just the first (#40533)
* Search all assigned ipv6 addresses instead of just the first * Add test for idempotency with multiple ipv6 addresses assigned
This commit is contained in:
parent
ed7d6d9c19
commit
e8d02a3a0f
2 changed files with 40 additions and 15 deletions
|
@ -148,9 +148,18 @@ def validate_param_values(module, obj, param=None):
|
||||||
def parse_config_argument(configobj, name, arg=None):
|
def parse_config_argument(configobj, name, arg=None):
|
||||||
cfg = configobj['interface %s' % name]
|
cfg = configobj['interface %s' % name]
|
||||||
cfg = '\n'.join(cfg.children)
|
cfg = '\n'.join(cfg.children)
|
||||||
match = re.search(r'%s (.+)$' % arg, cfg, re.M)
|
|
||||||
if match:
|
values = []
|
||||||
return match.group(1).strip()
|
matches = re.finditer(r'%s (.+)$' % arg, cfg, re.M)
|
||||||
|
for match in matches:
|
||||||
|
match_str = match.group(1).strip()
|
||||||
|
if arg == 'ipv6 address':
|
||||||
|
values.append(match_str)
|
||||||
|
else:
|
||||||
|
values = match_str
|
||||||
|
break
|
||||||
|
|
||||||
|
return values or None
|
||||||
|
|
||||||
|
|
||||||
def search_obj_in_list(name, lst):
|
def search_obj_in_list(name, lst):
|
||||||
|
@ -198,7 +207,7 @@ def map_obj_to_commands(updates, module):
|
||||||
commands.append('ip address {}'.format(ipv4))
|
commands.append('ip address {}'.format(ipv4))
|
||||||
|
|
||||||
if ipv6:
|
if ipv6:
|
||||||
if obj_in_have is None or obj_in_have.get('ipv6') is None or ipv6.lower() != obj_in_have['ipv6'].lower():
|
if obj_in_have is None or obj_in_have.get('ipv6') is None or ipv6.lower() not in [addr.lower() for addr in obj_in_have['ipv6']]:
|
||||||
commands.append('ipv6 address {}'.format(ipv6))
|
commands.append('ipv6 address {}'.format(ipv6))
|
||||||
|
|
||||||
if commands[-1] == interface:
|
if commands[-1] == interface:
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert: &unchanged
|
||||||
that:
|
that:
|
||||||
- 'result.changed == false'
|
- 'result.changed == false'
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
- '"ip address dhcp" in result.commands'
|
- '"ip address dhcp" in result.commands'
|
||||||
|
|
||||||
- name: Configure interface ipv6 address
|
- name: Configure interface ipv6 address
|
||||||
ios_l3_interface:
|
ios_l3_interface: &ipv6-1
|
||||||
name: "{{ test_interface }}"
|
name: "{{ test_interface }}"
|
||||||
ipv6: fd5d:12c9:2201:1::1/64
|
ipv6: fd5d:12c9:2201:1::1/64
|
||||||
state: present
|
state: present
|
||||||
|
@ -88,16 +88,36 @@
|
||||||
- '"ipv6 address fd5d:12c9:2201:1::1/64" in result.commands'
|
- '"ipv6 address fd5d:12c9:2201:1::1/64" in result.commands'
|
||||||
|
|
||||||
- name: Configure interface ipv6 address (idempotent)
|
- name: Configure interface ipv6 address (idempotent)
|
||||||
ios_l3_interface:
|
ios_l3_interface: *ipv6-1
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *unchanged
|
||||||
|
|
||||||
|
- name: Configure second ipv6 address on interface
|
||||||
|
ios_l3_interface: &ipv6-2
|
||||||
name: "{{ test_interface }}"
|
name: "{{ test_interface }}"
|
||||||
ipv6: fd5d:12c9:2201:1::1/64
|
ipv6: fd5d:12c9:2291:1::1/64
|
||||||
state: present
|
state: present
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- 'result.changed == false'
|
- 'result.changed == true'
|
||||||
|
- '"interface {{ test_interface }}" in result.commands'
|
||||||
|
- '"ipv6 address fd5d:12c9:2291:1::1/64" in result.commands'
|
||||||
|
|
||||||
|
- name: Ensure first ipv6 address still associated with interface
|
||||||
|
ios_l3_interface: *ipv6-1
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *unchanged
|
||||||
|
|
||||||
|
- name: Ensure second ipv6 address still associated with interface
|
||||||
|
ios_l3_interface: *ipv6-2
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert: *unchanged
|
||||||
|
|
||||||
- name: Assign same ipv6 address to other interface (fail)
|
- name: Assign same ipv6 address to other interface (fail)
|
||||||
ios_l3_interface:
|
ios_l3_interface:
|
||||||
|
@ -181,9 +201,7 @@
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert: *unchanged
|
||||||
that:
|
|
||||||
- 'result.changed == false'
|
|
||||||
|
|
||||||
- name: Change ipv4 and ipv6 address using aggregate
|
- name: Change ipv4 and ipv6 address using aggregate
|
||||||
ios_l3_interface:
|
ios_l3_interface:
|
||||||
|
@ -232,8 +250,6 @@
|
||||||
provider: "{{ cli }}"
|
provider: "{{ cli }}"
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert: *unchanged
|
||||||
that:
|
|
||||||
- 'result.changed == false'
|
|
||||||
|
|
||||||
- debug: msg="END ios_l3_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
- debug: msg="END ios_l3_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||||
|
|
Loading…
Reference in a new issue