Useful Links:
https://geektechstuff.com/2019/06/25/installing-ansible-raspberry-pi/
https://geektechstuff.com/2019/06/27/ansible-setting-up-ssh-raspberry-pi/
https://docs.ansible.com/projects/ansible/latest/reference_appendices/config.html#ansible-configuration-settings-locations
Did the install commands:
sudo apt-get update
sudo apt-get upgrade
sudo apt install ansible
this did not create the default directory /etc/ansible or the default config files so had to do the following:
sudo mkdir -p /etc/ansible
sudo touch /etc/ansible/ansible.cfg /etc/ansible/hosts
ansible-config init –disabled > ansible.cfg
sudo mv ansible.cfg /etc/ansible/ansible.cfg
Now check the config:
ansible –version
Now edited the hosts file for ansible
sudo pico -w /etc/ansible/hosts
and put in a test group:
[test]
192.168.0.1
192.168.0.2
errored as predicted in https://geektechstuff.com/2019/06/25/installing-ansible-raspberry-pi/ but I did not like the solution of ssh keys, so I found how to add name and password to host file:
[test]
192.168.0.212
[test:vars]
ansible_user=user
ansible_password=*******
and that worked for what I want (to be able to log into switches and routers to run commands
Host 192.168.0.*
kexalgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie- hellman-group1-sha1
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
Ciphers +aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc
had to modify hosts file as follows:
[sw]
192.168.0.12
192.168.0.22
192.168.0.32
192.168.0.42
[sw:vars]
ansible_connection=network_cli
ansible_network_os=cisco.ios.ios
ansible_user=______
ansible_password=_____
[router]
192.168.0.11
192.168.0.21
192.168.0.31
192.168.0.41
[router:vars]
ansible_connection-network_cli
ansible_network_os_cisco.ios.ios
ansible_user=______
ansible_password=_____
then got error saying I was missing paramiko so I had to do the following:
sudo apt-get update && sudo apt-get install -y python3-paramiko
After that I tested with the following command:
ansible sw -m ansible.netcommon.cli_command -a “command=’show ip interface brief'”
and got correct response from connected/configured switch! YAY!
other useful command for testing is:
ansible sw -m ansible.netcommon.cli_command -a “command=’show version | include Cisco IOS”
ansible sw -m ansible.netcommon.cli_command -a “command=’show version | include register”
Started working on my first playbooks…..
looking at:
https://github.com/colin-mccarthy/ansible-playbooks-for-cisco-ios
to execute playbook:
ansible-playbook playbook.yml
[note playbooks CAN have parameters passed to them…for example:
ansible-playbook playbook.yml -e “app_version=2.4.1 environment=production”
where {{ app_version }} will have the value of 2.4.1 and {{ environment }} will have value of production.