diff --git a/ansible/group_vars/switches/interfaces b/ansible/group_vars/switches/config similarity index 68% rename from ansible/group_vars/switches/interfaces rename to ansible/group_vars/switches/config index c24b68661..9af478b39 100644 --- a/ansible/group_vars/switches/interfaces +++ b/ansible/group_vars/switches/config @@ -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. diff --git a/ansible/group_vars/switches/dell b/ansible/group_vars/switches/dell index 760412acf..56d61538e 100644 --- a/ansible/group_vars/switches/dell +++ b/ansible/group_vars/switches/dell @@ -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 }}" diff --git a/ansible/physical-network.yml b/ansible/physical-network.yml index 1104515f3..86f6b6aa9 100644 --- a/ansible/physical-network.yml +++ b/ansible/physical-network.yml @@ -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 }}" diff --git a/ansible/roles/dell-switch/defaults/main.yml b/ansible/roles/dell-switch/defaults/main.yml new file mode 100644 index 000000000..dc49a7c40 --- /dev/null +++ b/ansible/roles/dell-switch/defaults/main.yml @@ -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: {} diff --git a/ansible/roles/dell-switch/tasks/main.yml b/ansible/roles/dell-switch/tasks/main.yml new file mode 100644 index 000000000..c48450b94 --- /dev/null +++ b/ansible/roles/dell-switch/tasks/main.yml @@ -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' }}" diff --git a/ansible/roles/dell-switch/templates/dellos6-config.j2 b/ansible/roles/dell-switch/templates/dellos6-config.j2 new file mode 100644 index 000000000..94c9dc068 --- /dev/null +++ b/ansible/roles/dell-switch/templates/dellos6-config.j2 @@ -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 %} diff --git a/ansible/roles/dell-switch/templates/dellos9-config.j2 b/ansible/roles/dell-switch/templates/dellos9-config.j2 new file mode 100644 index 000000000..66bba042e --- /dev/null +++ b/ansible/roles/dell-switch/templates/dellos9-config.j2 @@ -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 %}