Posts

Showing posts with the label Ansible

Ansible-Playbook to display output of multiple show commands (using stdout_lines with Loop)

 In this playbook, we we'll see how we can get display of multiple show commands in stdout_lines format. We can make use of loops (or with_items) for submitting multiple commands, but debug output with stdout_lines does not gives the formatted result as it would give for single command. So in case of multiple commands, we can debug the output of each command separately in stdout_lines format.

Ansible Playbook for Network OS Upgrade with pre and post checks

You have 100s of network switches or routers that you need to upgrade. How much time would it take for you to do the upgrades? There are a lot number of sub-tasks involved while upgrading IOS image of a Cisco router or a switch. This time of upgradation can be reduced through automation from various Enterprise Configuration Management tools that also have ability to upgrade network OS. Though these tools give an easy to use graphical interface, but this requires you to have appropriate license and also restricts you to customize your upgrade process.

Ansible to Configure DHCP IP-Helper Address on Multiple Devices

In this post we'll be configuring ip-helper address on multiple devices using Ansible. We'll be defining the interfaces to be configured for different devices in host_vars. In ansible, host-specific variables can be defined in the host_vars sub-directory either in the home directory of user executing ansible play or in /etc/ansible. Each file/directory in the host_vars sub-directory is name after the host it represents, e.g. host variable for device router-01 are stored in either ~/host_vars/router-01 or /etc/ansible/host_vars/router-01

[Video] Fetch Network Inventory from Ansible | Get Serial & model number and OS version of network devices

Image
Fetch Network inventory using Ansible. Depending upon what information we need, we can include the parameters in ansible-playbook. Using Ansible will really save time to accomplish many tasks that required to be performed on bulk devices.

[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

Configure interfaces with Ansible

 Today we will be configuring network devices from Ansible using ios_config module. Ansible playbook to create loopback interfaces and add description ---   - name: Define Parameters   hosts: XE   gather_facts: no   connection: network_cli   tasks:     - name: Create loopback interfaces       ios_config:         lines:           - description loopback interface by prashant         parents: "{{ item }}"       with_items:           - interface loopback 25           - interface loopback 30           - interface loopback 35

Ansible-playbook for backing up running config of Cisco IOS

This ansible-playbook can be used to backup running configuration from Cisco IOS devices. You can refer to my earlier post Getting Started with your first ansible-playbook for Network Automation  to know about the parameters used in this playbook. Inventory file # 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 [all:vars] ansible_network_os=ios Playbook --- - name: Define Parameters   hosts: XE   gather_facts: no   connection: network_cli   tasks:    - name: backup the config      ios_config:       backup: yes      register: backup_config    - name: Store the config to directory      copy:       src: "{{ backup_config.backup_path }}"       dest: "/tmp/backups/{{ inventory_hostname }}" Running the playbook [prashant@Prashant-VM01 ~]$ ansible-playbook play03.yml -i /home/prasha...