From 0bd99aef082b556a982a7920af15e6b5a02bc7d6 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 22 Jun 2019 09:13:20 +0200 Subject: dellos6: basic interface manangement --- inventory/group_vars/dellos6/main.yml | 17 ++++++++++++++ roles/dellos6/layer2/tasks/main.yml | 16 ++++++++++--- roles/dellos6/layer2/templates/interfaces.j2 | 34 ++++++++++++++++++++++++++++ roles/dellos6/layer2/templates/vlan.j2 | 5 ---- roles/dellos6/layer2/templates/vlans.j2 | 5 ++++ 5 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 roles/dellos6/layer2/templates/interfaces.j2 delete mode 100644 roles/dellos6/layer2/templates/vlan.j2 create mode 100644 roles/dellos6/layer2/templates/vlans.j2 diff --git a/inventory/group_vars/dellos6/main.yml b/inventory/group_vars/dellos6/main.yml index 7bf53699..0cb2bcda 100644 --- a/inventory/group_vars/dellos6/main.yml +++ b/inventory/group_vars/dellos6/main.yml @@ -18,3 +18,20 @@ dellos6_vlans_yaml: | - name: "{{ zone_name }}" id: "{{ switch_network_zones[zone_name].vlan }}" {% endfor %} + +dellos6_interfaces: "{{ dellos6_interfaces_yaml | from_yaml }}" +dellos6_interfaces_yaml: | + - spec: range Gi1/0/5-27 + vlan: 28 + - spec: Te1/0/1 + description: "to sw1" + switchport_mode: trunk + # - spec: range Te1/0/3-4 + # channel_group: 1 + - spec: Po1 + description: "fileserver" + switchport_mode: general + allowed_vlans: + - 28 + - 32 + - 30 diff --git a/roles/dellos6/layer2/tasks/main.yml b/roles/dellos6/layer2/tasks/main.yml index 75617b1c..a9383e5f 100644 --- a/roles/dellos6/layer2/tasks/main.yml +++ b/roles/dellos6/layer2/tasks/main.yml @@ -1,6 +1,16 @@ --- -- name: create vlans +# - name: configure vlans +# dellos6_config: +# src: vlans.j2 +# replace: block +# notify: save configuration + +- pause: + prompt: "\n\n{{ lookup('template', 'interfaces.j2') }}\n\n" + delegate_to: localhost + +- name: configure interfaces dellos6_config: - src: vlan.j2 + src: interfaces.j2 + replace: block notify: save configuration - register: vlan_result diff --git a/roles/dellos6/layer2/templates/interfaces.j2 b/roles/dellos6/layer2/templates/interfaces.j2 new file mode 100644 index 00000000..28ec1341 --- /dev/null +++ b/roles/dellos6/layer2/templates/interfaces.j2 @@ -0,0 +1,34 @@ +{% for interface in dellos6_interfaces %} +interface {{ interface.spec }} +{% if 'description' in interface %} +description "{{ interface.description }}" +{% endif %} +{% if 'channel_group' in interface %} +channel-group {{ interface.channel_group }} mode active +{% endif %} +switchport mode {{ interface.switchport_mode | default('access') }} +{% if 'switchport_mode' not in interface or interface.switchport_mode == 'access' %} +{% if 'vlan' in interface %} +switchport access vlan {{ interface.vlan }} +{% endif %} +{% elif interface.switchport_mode == 'trunk' %} +{% if 'pvid' in interface %} +switchport trunk native vlan {{ interface.pvid }} +{% endif %} +{% elif interface.switchport_mode == 'general' %} +{% if 'tagged_only' in interface and interface.tagged_only %} +switchport general acceptable-frame-type tagged-only +{% endif %} +{% if 'ingress_filtering' in interface and not interface.ingress_filtering %} +switchport general ingress-filtering disable +{% endif %} +{% if 'forbidden_vlans' in interface %} +switchport general forbidden vlan add {{ interface.forbidden_vlans | join(',') }} +{% endif %} +switchport general allowed vlan add {{ interface.allowed_vlans | join(',') }} +{% if 'pvid' in interface %} +switchport general pvid {{ interface.pvid }} +{% endif %} +{% endif %} +exit +{% endfor %} diff --git a/roles/dellos6/layer2/templates/vlan.j2 b/roles/dellos6/layer2/templates/vlan.j2 deleted file mode 100644 index 6403c735..00000000 --- a/roles/dellos6/layer2/templates/vlan.j2 +++ /dev/null @@ -1,5 +0,0 @@ -{% for vlan in dellos6_vlans %} -vlan {{ vlan.id }} -name "{{ vlan.name }}" -exit -{% endfor %} diff --git a/roles/dellos6/layer2/templates/vlans.j2 b/roles/dellos6/layer2/templates/vlans.j2 new file mode 100644 index 00000000..6403c735 --- /dev/null +++ b/roles/dellos6/layer2/templates/vlans.j2 @@ -0,0 +1,5 @@ +{% for vlan in dellos6_vlans %} +vlan {{ vlan.id }} +name "{{ vlan.name }}" +exit +{% endfor %} -- cgit v1.2.3