Ansible Switch Configuration

Author: R Zach Feeser

Ansible is able to change the configuration of network devices. In this exercise, we will change the configuration of an Arista Switch.

Step 1 - cat the ansible hosts file

student@beachhead: cat hosts

172.16.2.10
172.16.2.20

Step 2 - Check ssh connectivity to the first host. It works!

student@beachhead: ssh admin@172.16.2.10

Password :
Last login: Wed Aug 22 19:13:24 2018 from 172.16.2.100 SW1>
SW1>
SWl>exit
Connection to 172.16.2.10 closed.	

Step 3 - Check ssh connectivity to the second host. It works too!

student@beachhead: ssh admin@172.16.2.20

student@beachhead:-/net01$ 
ssh admin@172.16.2.20 
Password :
Last login: Wed Aug 22 19:16:07 2018 from 172.16.2.100 
SW2>
SW2>exit
Connection to 172.16.2.20 closed. 

Step 4 - cat the ansible playbook and study it line by line.

Ultimately, all this playbook is going to do is change the login banner, a very safe thing to do as a first attempt!

student@beachhead:$ cat netOl.yml

- name: My Arista Playbook 
  hosts: all 
  gatherfacts: false
  vars:
    ansibleconnection: networkcli 
    ansible network os: 
    eos ansible_become: yes 
    ansiblebecomemethod: enable 
    ansible user: admin 
    ansible_ssh_pass: alta3
    
  tasks:
  - name: configure the login banner 
    eosbanner: 
      authorize: yes 
  	banner: login 
  	text: | 
  	  Congrats! You set a banner using an Ansible EOS module. 
  	  Notice how YAML formatting lets us do multi-line strings
  	state: present  

Step 5 - Check out the EOS ansible module documentation

https://docs.ansible.com/ansible/2.10/collections/arista/eos/eos_banner_module.html

Step 6 - Run the playbook. It works!

student@beachhead:$ ansible-playbook -i hosts netOl.yml

PLAY [My Arista Playbook] ****************************************************
TASK [configure the login banner] ********************************************
changed: [172.16.2.10]"
changed: [172.16.2.20]

PLAY RECAP ******************************************************************* 
172.16.2.10	: ok=l	changed=1	unreachable=0	failed=0
172.16.2.20	: ok=l	changed=l	unreachable=0	failed=0	

Step 7 - Confirm that the changes were made. Testing shows that it worked!

student@beachhead:$ ssh admin@172.16.2.10

Congrats! You set a banner using an Ansible EOS module 
Notice how YAML formatting lets us do multi-line strings 
Password:

student@beachhead:$ ssh admin@172.16.Z-20

Congrats! You set a banner using an Ansible EOS module 
Notice how YAML formatting lets us do multi-line strings 
Password:

Step 8 - Demonstrate the power of ansible by making a single parameter change.

- name: My Arista Playbook 
 hosts: all 
 gatherfacts: false
 vars:
   ansibleconnection: networkcli 
   ansible network os: 
   eos ansible_become: yes 
   ansiblebecomemethod: enable 
   ansible user: admin 
   ansible_ssh_pass: alta3
   
 tasks:
 - name: configure the login banner 
   eosbanner: 
     authorize: yes 
 	banner: login 
 	text: | 
 	  Congrats! You set a banner using an Ansible EOS module. 
 	  Notice how YAML formatting lets us do multi-line strings
 	state: present  # <----- CHANGE THIS LINE TO state: absent

Step 9 - Run the playbook again.

student@beachhead:$ ansible-playbook -i hosts netOl.yml

PLAY [My Arista Playbook] ****************************************************
TASK [configure the login banner] ********************************************
changed: [172.16.2.10]"
changed: [172.16.2.20]

PLAY RECAP ******************************************************************* 
172.16.2.10	: ok=l	changed=1	unreachable=0	failed=0
172.16.2.20	: ok=l	changed=l	unreachable=0	failed=0	

Step 10 - Confirm that the changes were made. No more login banner. It worked!

student@beachhead:$ ssh admin@172.16.2.10

Password:
← Previous Next →