-
-
Save wate/85790e5438b28b3be9790a085acdd214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: init vars | |
set_fact: | |
dummy_interface_commands: [] | |
- name: add delete command | |
set_fact: | |
dummy_interface_commands: '{{ dummy_interface_commands }} + ["delete interfaces dummy {{ item.key }}"]' | |
when: | |
- item.value.state|default('present') == 'absent' | |
- item.key in dummy_interfaces | |
- name: add set command | |
set_fact: | |
dummy_interface_commands: '{{ dummy_interface_commands }} + ["set interfaces dummy {{ item.key }} address {{ item.value.ipv4 }}"]' | |
when: | |
- item.value.state|default('present') == 'present' | |
- item.key not in dummy_interfaces | |
- item.value.ipv4 is defined | |
- name: add set command | |
set_fact: | |
dummy_interface_commands: '{{ dummy_interface_commands }} + ["set interfaces dummy {{ item.key }} address {{ item.value.ipv6 }}"]' | |
when: | |
- item.value.state|default('present') == 'present' | |
- item.key not in dummy_interfaces | |
- item.value.ipv6 is defined | |
- name: add set description command | |
set_fact: | |
dummy_interface_commands: '{{ dummy_interface_commands }} + ["set interfaces dummy {{ item.key }} description {{ item.value.description }}"]' | |
when: | |
- item.value.state|default('present') == 'present' | |
- item.value.description is defined | |
- vyos_command: | |
commands: "{{ dummy_interface_commands }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- vyos_l3_interface: | |
name: "{{ item.key }}" | |
ipv4: "{{ item.value.ipv4|default(omit) }}" | |
ipv6: "{{ item.value.ipv6|default(omit) }}" | |
state: "{{ item.value.state|default('present') }}" | |
when: item.value.state|default('present') in ['present', 'absent'] | |
- vyos_interface: | |
name: "{{ item.key }}" | |
description: "{{ item.value|default(omit) }}" | |
address: "{{ item.value.address|default(omit) }}" | |
duplex: "{{ item.value.duplex|default(omit) }}" | |
mtu: "{{ item.value.mtu|default(omit) }}" | |
speed: "{{ item.value.speed|default(omit) }}" | |
state: "{{ item.value.state|default('present') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: sample | |
hosts: all | |
become: yes | |
vars: | |
vyos_ethernet_interfaces: | |
eth0: | |
ipv4: dhcp | |
state: parent | |
vyos_dummy_interfaces: | |
dum0: | |
ipv4: 10.2.0.1/24 | |
description: "description" | |
state: present | |
dum1: | |
ipv4: 10.2.1.1/24 | |
state: absent | |
tasks: | |
- name: manage ethernet interface | |
include_tasks: ethernet_interface.yml | |
with_dict: "{{ vyos_ethernet_interfaces }}" | |
- name: manage dummy interface | |
block: | |
- name: get registered dummy interfaces | |
vyos_command: | |
commands: | |
- "show interfaces dummy | tail -n +4 | awk '{print $1}'" | |
changed_when: false | |
register: result | |
- set_fact: | |
dummy_interfaces: result.stdout_lines | |
- name: manage dummy interface | |
include_tasks: dummy_interface.yml | |
with_dict: "{{ vyos_dummy_interfaces }}" | |
when: vyos_dummy_interfaces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment