Posts

Showing posts from April, 2020

[Video] Install Ansible and run your first playbook

Image
Are you a network engineer and want to know from where to start network automation? Or want to learn how to install and configure Ansible server for running your first ansible-playbook on Ansible.  

RSA key save Error Resolution in Ansible

If you are also struggling while running ansible-plabook for new hosts and getting error like following, then you have two options. Either connect to each host one by one to save the RSA keys of that host to your ansible server or you can disable host key checking in ansible configuration file. Here is the way to do it Edit/create either of the following files  /etc/ansible/ansible.cfg or ~/.ansible.cfg and add the following to the file. [defaults] host_key_checking = False

Ansible - Network Debug and Troubleshooting

There may be some times when you are trying to run an ansible-playbook that you created but getting errors that you are not able to understand. To understand why ansible-playbook is not working, we can enable debugging and logging to understand what is going wrong. Following are the steps to enable logging in ansible. Before running ansible-playbook run the following commands to enable logging: # Specify the location for the log file export ANSIBLE_LOG_PATH=~/ansible.log # Enable Debug export ANSIBLE_DEBUG=True # Run with 4*v for connection level verbosity ansible-playbook -vvvv ... After Ansible has finished running you can inspect the log file which has been created on the ansible-controller: less $ANSIBLE_LOG_PATH 2017-03-30 13:19:52,740 p=28990 u=fred |  creating new control socket for host veos01:22 as user admin 2017-03-30 13:19:52,741 p=28990 u=fred |  control socket path is /home/fred/.ansible/pc/ca5960d27a 2017-03-30 13:19:52,741 p=28990 u=fred |  current working...

Get Model Number and Serial number of Cisco devices using ios_facts module

 This ansible-playbook will get the model number and serial number of Cisco devices using ios_facts module --- - name: Define Parameters   hosts: XE   gather_facts: no   connection: network_cli   tasks:    - name: Get the facts      ios_facts:        gather_subset: all    - name: Display model and serial number      debug:        msg: "Model number of {{ ansible_net_hostname }} is {{ ansible_net_model }} and serial number is {{ ansible_net_serialnum }}" ~ ~ https://docs.ansible.com/ansible/latest/modules/ios_facts_module.html

Adding and Editing ACL on Cisco IOS using Ansible

Ansible playbook for adding a new ACL to Cisco IOS devices. --- - name: Define Paramenters   hosts: XE   connection: network_cli   tasks:     - name: load new acl into device       ios_config:         lines:           - 10 permit ip host 192.0.2.1 any log           - 20 permit ip host 192.0.2.2 any log           - 30 permit ip host 192.0.2.3 any log           - 40 permit ip host 192.0.2.4 any log           - 50 permit ip host 192.0.2.5 any log           - 60 permit ip host 192.0.2.6 any log         parents: ip access-list extended test         before: no ip access-...

Specifying SSH port in Ansible Inventory

There may be some instances where you set a custom port for SSH on your network device. If ssh port for hosts is different than the default port 22, it can be specified in the inventory file with colon (:) after hostname. #vi inventory # Inventory file for Ansible   [XE] ios-xe-mgmt.cisco.com:8181 ios-xe-mgmt-latest.cisco.com:8181   [XR] sbx-iosxr-mgmt.cisco.com:8181