Ansible

https://learningnetwork.cisco.com/blogs/vip-perspectives/2017/08/10/automating-cisco-using-ansible

https://www.ansible.com/blog/network-device-authentication-with-ansible-2-3

https://docs.ansible.com/ansible/2.5/user_guide/vault.html

https://networklore.com/ansible-ios_config/

…https://www.youtube.com/watch?v=7RBs7JFj4xI…

To install -> python3.7 -m pip install ansible;

/etc/ansible/ansible.cfg; to manage config globally and you may also have a .ansible.cfg in home directory for user based configurations. You may need the .ansible.cfg to be in the CWD of where you are running ansible from.

For Linux: ssh-keygen; generate keys -> ssh-copy-id UsEr@10.1.1.1; ssh UsEr@10.1.1.1; enables you to login from the automation machine without a password.

The inventory file identifies hosts and groups of hosts for ansible to communicate with. Typically there will be a file called hosts in the CWD where these hosts are outlined. Hosts can use IP or FQDN.

Ansible-hosts

The red box shows how to specify python interpreter.

CLI commands:

ansible-CLI

Running a command ad hoc:

ansible-cli-ad-hoc

Utilizing ansible:

ansible-tools

Playbook:

ansible-playbook-slide.PNG

The number 1 & 2 to the left represent two different plays. The number 3 represents the 3rd task in the second playbook.  You can see in task 2 that we are gathering the data from netstat -rn and registering it so then it could be printed with that 3rd task. If the file above was called example1.yaml below is how we would call on it.

ansible-playbook -u root example1.yaml; if you do not specify the user it will try and use the user you are currently using to run the shell that is calling this ansible command.

How to use variables and loops:

ansible-variables-loops

Host and group variables:

ansible-host-and-group-variables

Jinja2:

ansible-Jinja2

Ansible specifics for network devices:

We use connection : local to run the code local so that ansible doesn’t run the python modules on the host devices. Our network devices may not support python.

ansible-local-network-devices

Logging into network devices a lot of the time we use username and passwords and generally do not use keys. Below shows how to do that.

ansible-network-devices-username

An example playbook for NXOS:

ansible-playbook-for-nxos

A little more complex:

ansible-a-little-more-complex-still-nxos

Example of how to use parents:

ansible-example-of-PARENTS

Just as you configure routing protocols under the-> router ospf 51; network  1.1.1.1 0.0.0.0 area 51; you would need the first command to be second and be a parent.

How to push a config from a file and save it:

ansible-push-config-file-and-save

Different ways to use the host file: Switches says needs to be tested. It was and behaved as expected!

ansible-host-file-example

You can also get two or more lists of device into another group. Both Distribution switches and Access switched belong to the group Both switches.

Ansible-hosts-other-way-with-children There is a typo here. 😉 It happens.

How to copy the running config or any command to local device(Ansible Server):

ansible-copy-run-to-automation-machine

Basic loop with Ansible:

ansible-onehost-loopbacks

Encrypted username and passwords:

I wrestled with the docs until I came across this handy walk-through https://gist.github.com/tristanfisher/e5a306144a637dc739e7…   Remove last 3 decimals I added them so page would not open here.

https://gist.github.com/tristanfisher/e5a306144a637dc739e7…

 

 

Leave a comment