Move Dell switch configuration to a dell-switch role
This encapsulates the differences between switch OS modules. Also add support for global switch configuration.
This commit is contained in:
parent
12884dd121
commit
17ce724fa4
@ -1,6 +1,13 @@
|
||||
---
|
||||
# Switch configuration.
|
||||
|
||||
###############################################################################
|
||||
# Global configuration.
|
||||
|
||||
# Global configuration. A list of configuration lines to be applied at the
|
||||
# global level.
|
||||
switch_config: []
|
||||
|
||||
###############################################################################
|
||||
# Interface configuration.
|
||||
|
@ -4,9 +4,9 @@
|
||||
###############################################################################
|
||||
# Authentication configuration.
|
||||
|
||||
# For DellOS6 switches, this defines a 'provider' argument to the dellos6_*
|
||||
# For DellOS switches, this defines a 'provider' argument to the dellos_*
|
||||
# modules.
|
||||
switch_dellos6_provider:
|
||||
switch_dellos_provider:
|
||||
host: "{{ ansible_host }}"
|
||||
username: "{{ ansible_user }}"
|
||||
password: "{{ ansible_ssh_pass }}"
|
||||
|
@ -10,17 +10,13 @@
|
||||
group_by:
|
||||
key: "switches_of_type_{{ switch_type }}"
|
||||
|
||||
- name: Ensure DellOS6 physical network devices are configured
|
||||
hosts: switches_of_type_dellos6
|
||||
- name: Ensure DellOS physical switches are configured
|
||||
hosts: switches_of_type_dellos6:switches_of_type_dellos9
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- name: Ensure DellOS6 switch interfaces are configured
|
||||
local_action:
|
||||
module: dellos6_config
|
||||
provider: "{{ switch_dellos6_provider }}"
|
||||
lines: >
|
||||
{{ ['description ' ~ item.value.description] +
|
||||
item.value.config | default([]) }}
|
||||
parents:
|
||||
- "interface {{ item.key }}"
|
||||
with_dict: "{{ switch_interface_config }}"
|
||||
roles:
|
||||
- role: dell-switch
|
||||
dell_switch_delegate_to: localhost
|
||||
dell_switch_type: "{{ switch_type }}"
|
||||
dell_switch_provider: "{{ switch_dellos_provider }}"
|
||||
dell_switch_config: "{{ switch_config }}"
|
||||
dell_switch_interface_config: "{{ switch_interface_config }}"
|
||||
|
17
ansible/roles/dell-switch/defaults/main.yml
Normal file
17
ansible/roles/dell-switch/defaults/main.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
# Host on which to execute DellOS Ansible modules.
|
||||
dell_switch_delegate_to:
|
||||
|
||||
# Type of Dell switch. One of dellos6, dellos9.
|
||||
dell_switch_type:
|
||||
|
||||
# Authentication provider information.
|
||||
dell_switch_provider:
|
||||
|
||||
# List of configuration lines to apply to the switch.
|
||||
dell_switch_config: []
|
||||
|
||||
# Interface configuration. Dict mapping switch interface names to configuration
|
||||
# dicts. Each dict contains a 'description' item and a 'config' item which
|
||||
# should contain a list of per-interface configuration.
|
||||
dell_switch_interface_config: {}
|
14
ansible/roles/dell-switch/tasks/main.yml
Normal file
14
ansible/roles/dell-switch/tasks/main.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Ensure DellOS6 switches are configured
|
||||
dellos6_config:
|
||||
provider: "{{ dell_switch_provider }}"
|
||||
src: dellos6-config.j2
|
||||
delegate_to: "{{ dell_switch_delegate_to }}"
|
||||
when: "{{ dell_switch_type == 'dellos6' }}"
|
||||
|
||||
- name: Ensure DellOS9 switches are configured
|
||||
dellos9_config:
|
||||
provider: "{{ dell_switch_provider }}"
|
||||
src: dellos9-config.j2
|
||||
delegate_to: "{{ dell_switch_delegate_to }}"
|
||||
when: "{{ dell_switch_type == 'dellos9' }}"
|
16
ansible/roles/dell-switch/templates/dellos6-config.j2
Normal file
16
ansible/roles/dell-switch/templates/dellos6-config.j2
Normal file
@ -0,0 +1,16 @@
|
||||
#jinja2: trim_blocks: True,lstrip_blocks: True
|
||||
|
||||
{% for line in dell_switch_config %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
|
||||
{% for interface, config in dell_switch_interface_config.items() %}
|
||||
interface {{ interface }}
|
||||
{% if config.description is defined %}
|
||||
description {{ config.description }}
|
||||
{% endif %}
|
||||
{% for line in config.config %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
exit
|
||||
{% endfor %}
|
35
ansible/roles/dell-switch/templates/dellos9-config.j2
Normal file
35
ansible/roles/dell-switch/templates/dellos9-config.j2
Normal file
@ -0,0 +1,35 @@
|
||||
#jinja2: trim_blocks: True,lstrip_blocks: True
|
||||
|
||||
{% for line in dell_switch_config %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
|
||||
{# Configure all ethernet interfaces first, then configure VLAN interfaces #}
|
||||
{# which may depend on them. #}
|
||||
|
||||
{% for interface, config in
|
||||
dell_switch_interface_config.items() %}
|
||||
{% if 'vlan' not in interface %}
|
||||
interface {{ interface }}
|
||||
{% if config.description is defined %}
|
||||
description {{ config.description }}
|
||||
{% endif %}
|
||||
{% for line in config.config %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
exit
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% for interface, config in dell_switch_interface_config.items() %}
|
||||
{% if 'vlan' in interface %}
|
||||
interface {{ interface }}
|
||||
{% if config.description is defined %}
|
||||
description {{ config.description }}
|
||||
{% endif %}
|
||||
{% for line in config.config %}
|
||||
{{ line }}
|
||||
{% endfor %}
|
||||
exit
|
||||
{% endif %}
|
||||
{% endfor %}
|
Loading…
x
Reference in New Issue
Block a user