diff --git a/ansible/group_vars/all/switches/arista b/ansible/group_vars/all/switches/arista new file mode 100644 index 000000000..37d38e6de --- /dev/null +++ b/ansible/group_vars/all/switches/arista @@ -0,0 +1,22 @@ +--- +# Switch configuration. + +############################################################################### +# Authentication configuration. + +# For Arista switches, this defines a 'provider' argument to the eos_* +# modules. +switch_arista_provider: + host: "{{ ansible_host }}" + username: "{{ ansible_user }}" + password: "{{ ansible_ssh_pass }}" + transport: cli + authorize: yes + auth_pass: "{{ switch_auth_pass }}" + timeout: "{{ switch_arista_timeout }}" + +############################################################################### +# Timeout in seconds for completion of the switch config as a transaction +switch_arista_timeout: 60 + +... diff --git a/ansible/physical-network.yml b/ansible/physical-network.yml index 92354209d..ec038faa1 100644 --- a/ansible/physical-network.yml +++ b/ansible/physical-network.yml @@ -24,6 +24,7 @@ physical_network_display: False # List of supported values for the 'switch_type' variable. supported_switch_types: + - arista - dellos6 - dellos9 - dell-powerconnect @@ -94,6 +95,18 @@ debug: var: switch_interface_config +- name: Ensure Arista physical switches are configured + hosts: switches_of_type_arista:&switches_in_display_mode_False + gather_facts: no + roles: + - role: ssh-known-host + + - role: arista-switch + arista_switch_type: "{{ switch_type }}" + arista_switch_provider: "{{ switch_arista_provider }}" + arista_switch_config: "{{ switch_config }}" + arista_switch_interface_config: "{{ switch_interface_config }}" + - name: Ensure DellOS physical switches are configured hosts: switches_of_type_dellos6:switches_of_type_dellos9:&switches_in_display_mode_False gather_facts: no diff --git a/ansible/roles/arista-switch/README.md b/ansible/roles/arista-switch/README.md new file mode 100644 index 000000000..ca80dbae4 --- /dev/null +++ b/ansible/roles/arista-switch/README.md @@ -0,0 +1,81 @@ +Arista Switch +============= + +This role configures Arista switches using the `eos` Ansible +modules. It provides a fairly minimal abstraction of the configuration +interface provided by the `eos` modules, allowing for application of +arbitrary switch configuration options. + +Requirements +------------ + +The Ansible network modules for Arista require EOS 4.15 or later. + +The switches should be configured to allow SSH access. + +Role Variables +-------------- + +`arista_switch_provider` is authentication provider information passed as the +`provider` argument to the `eos` modules. + +`arista_switch_config` is a list of configuration lines to apply to the switch, +and defaults to an empty list. + +`arista_switch_interface_config` contains interface configuration. It is a dict +mapping switch interface names to configuration dicts. Each dict may contain +the following items: + +- `description` - a description to apply to the interface. +- `config` - a list of per-interface configuration. + +Dependencies +------------ + +None + +Example Playbook +---------------- + +The following playbook configures hosts in the `arista-switches` group. +It assumes host variables for each switch holding the host, username and +passwords. It applies global configuration for LLDP, and enables two +10G ethernet interfaces as switchports. + + --- + - name: Ensure Arista switches are configured + hosts: arista-switches + gather_facts: no + roles: + - role: arista-switch + arista_switch_provider: + host: "{{ switch_host }}" + username: "{{ switch_user }}" + password: "{{ switch_password }}" + transport: cli + authorize: yes + auth_pass: "{{ switch_auth_pass }}" + timeout: 60 + arista_switch_config: + - "lldp run" + - "lldp tlv-select system-name" + - "lldp tlv-select management-address" + - "lldp tlv-select port-description" + arista_switch_interface_config: + Et4/5: + description: server-1 + config: + - "no shutdown" + - "switchport" + Et4/7: + description: server-2 + config: + - "no shutdown" + - "switchport" + +Author Information +------------------ + +- Stig Telfer () + +Based on the dell-switch role by Mark Goddard () diff --git a/ansible/roles/arista-switch/defaults/main.yml b/ansible/roles/arista-switch/defaults/main.yml new file mode 100644 index 000000000..25aac60f6 --- /dev/null +++ b/ansible/roles/arista-switch/defaults/main.yml @@ -0,0 +1,11 @@ +--- +# Authentication provider information. +arista_switch_provider: + +# List of configuration lines to apply to the switch. +arista_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. +arista_switch_interface_config: {} diff --git a/ansible/roles/arista-switch/tasks/main.yml b/ansible/roles/arista-switch/tasks/main.yml new file mode 100644 index 000000000..7566cbfb2 --- /dev/null +++ b/ansible/roles/arista-switch/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: Ensure Arista switches are configured + local_action: + module: eos_config + provider: "{{ arista_switch_provider }}" + src: arista-config.j2 diff --git a/ansible/roles/arista-switch/templates/arista-config.j2 b/ansible/roles/arista-switch/templates/arista-config.j2 new file mode 100644 index 000000000..2d9254f8a --- /dev/null +++ b/ansible/roles/arista-switch/templates/arista-config.j2 @@ -0,0 +1,17 @@ +#jinja2: trim_blocks: True,lstrip_blocks: True + +{% for line in arista_switch_config %} +{{ line }} +{% endfor %} + +{% for interface, config in +arista_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/releasenotes/notes/arista-switch-aedc46148506c56e.yaml b/releasenotes/notes/arista-switch-aedc46148506c56e.yaml new file mode 100644 index 000000000..8d525c23f --- /dev/null +++ b/releasenotes/notes/arista-switch-aedc46148506c56e.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds support for configuration of Arista switches running EOS 4.15 or + later. This is integrated with the `kayobe physical network configure` + command.