Adds support to validate nested subspecs for conditional like mutually_exclusive, required_if,
required_one_of and required_together.
Returns the expanded role spec params initialized with default values as result of
validate_role_spec task, this result can be used in later task to set the expanded role spec
variables to it's default value
eg Playbook:
---
- hosts: localhost
connection: local
gather_facts: no
vars:
mlag_setup:
peer: test
ipaddr: value
tasks:
- name: set role path
set_fact:
role_path: ../ansible-network.network-engine
- name: import role
import_role:
name: ../ansible-network.network-engine
- name: validate spec
validate_role_spec:
spec: mlag_setup_spec.yaml
register: role_spec
- name: set role params
set_fact:
"{{ item.key }}": "{{ item.value }}"
loop: "{{ lookup('dict', role_spec.role_params, wantlist=True) }}"
- name: print role variables
debug:
msg: "{{ mlag_setup }}"
Contents of spec file:
$ cat mlag_setup_spec.yaml
---
argument_spec:
mlag_setup:
type: dict
options:
state:
type: str
required: false
default: present
choices:
- "present"
- "absent"
description:
- "Desired state: present, absent"
peer:
type: str
required: true
description:
- "The MLAG peer switch hostname (inventory_hostname)"
vlan:
type: int
required: false
default: "4094"
description:
- "VLAN to use for peer communication."
- "VLAN is used to create the interface vlan for MLAG_CONTROL_PLANE."
domain:
type: int
required: false
default: "1"
description:
- "Represents the MLAG domain."
- "The ID must be the same only for members of the same MLAG domain."
- "Domain is used to create the MLAG_CONTROL_PLANE VRF with RD <site>:<domain>"
site:
type: int
required: false
default: "1"
description:
- "Represents the site where the domain is located."
- "Site is used to create the MLAG_CONTROL_PLANE interface with address 169.254.<domain>.<site><device>"
- "Site is used to create the MLAG_CONTROL_PLANE VRF with RD <site>:<domain>"
device:
type: int
required: false
default: "1"
description:
- "Unique ID to represent the device member of the MLAG domain"
- "The ID is used to create the peer communication address 169.254.<domain>.<site><device>"
linkagg:
type: int
required: false
default: "1"
description:
- "Linkagg to use for the peer-to-peer communication."
vlans:
type: list
required: false
default:
- "all"
description:
- "List of vlans member of the MLAG domain"
- "VLANs are NOT created if they do not exist"
interlinks:
type: list
required: false
default:
- "Ethernet1"
description:
- "List of physical interfaces used by linkagg as interlinks for the peer-to-peer communication"
heartbeat:
type: int
default: "10000"
required: false
description:
- "Timer for heartbeat in ms"
reload_delay:
type: int
default: "150"
required: false
description:
- "Delay to bring MLAGs up after reload."
- "Helps to ensure that MLAGs comes up only when adjacency is done and tables are pre-populated."
- "Prevents blackhole of traffic when device is converging and tables being populated after a reboot."
ipv4:
type: str
required: true
description:
- "IPV4 address to use for the MLAG intercommunication"
aliases:
- ipaddr
vrf:
type: str
required: false
default: "mlag_control"
description:
- "The VRF name for the MLAG intercommunication"
extension:
type: dict
required: false
description:
- "Extension of specs with platform-specific keys/values"
Fixes https://github.com/ansible-network/network-engine/issues/189
mutually_exclusive
,required_if
,required_one_of
andrequired_together
.validate_role_spec
task, this result can be used in later task to set the expanded role spec variables to it's default valueeg Playbook:
Contents of spec file:
Ansible run output logs: