Using Ansible for Network Automation

Ansible is a tool used to automate Server provisioning and network provisioning.  Ansible is completely free!  You can dive deep into Ansible at their web site.

A great way to learn Ansible as a network automation tool is to use it in an emulated network environment. GNS3 fits that requirement perfectly.  GNS3 is also completely free!

As many of you know, we have been users of GNS3 since forever, plus we were part of their crowd sourcing!

GNS3 has evolved tremendously in the past years. Using the versions after 2.x brings great functionality into GNS3 including Ansible. We strongly urge students to use GNS3 to learn Ansible. If you want to learn how to install and use GNS3, there is a separate reference here.  Assuming you have version 2.x or later of GNS3 running, we will show how to accomplish this in a couple of simple videos below.

Even if you have never used GNS3, you can watch the videos below to get a clear understanding of how Ansible works!

Watch this video first to see exactly how to get Ansible with your GNS3 environment.

Install Ansible in GNS3 from Andrew Walding on Vimeo.

 The next step is to configure IP addresses:

 

 

 Here is the router configuration used:

enable
configure terminal
hostname R1
alias exec s show run
alias exec c config terminal
alias exec i show ip interface brief
alias exec ipr show ip route
ip tcp synwait 5
no service timestamps
no service time debug
line console 0
no login
no exec-timeout
logging synch
privilege level 15
line aux 0
no login
no exec-timeout
logging synch
privilege level 15
line vty 0 4
login local
transport input all
ip domain-name cellstream.com
crypto key generate rsa
1024
interface f0/0
ip address 192.168.1.101 255.255.255.0
no shutdown
username student pass csi123
username student priv 15
end
write

Now let’s add some routers into the topology:

 

 Now it is time to set up a simple Ansible environment. We will create a simple ansible.cfg file and a hosts file so ansible will be able to work with our routers:

 

 It’s finally time to actually create an Ansible playbook and run it against our topology. You will find the playbook1.yml file available to download below the video.

 

 Here is the playbook1.yml content:

---
- name: Install OSPF
  hosts: [gns3routers]
  gather_facts: false
  connection: local

  vars:
    cli:
      username: student
      password: csi123
      transport: cli

  tasks:
    - name: enable ospf
      ios_config:
        provider: "{{ cli }}"
        authorize: yes
        parents: router ospf 1
        lines:
          - network 0.0.0.0 255.255.255.255 area 0

      register: print_output

    - debug: var=print_output

 

I hope you find this article and its content helpful.  Comments are welcomed below.  If you would like to see more articles like this, please support us by clicking the patron link where you will receive free bonus access to courses and more, or simply buying us a cup of coffee!, and all comments are welcome! 

Leave a Comment

Contact Us Here


Please verify.
Validation complete :)
Validation failed :(
 
Your contact request has been received. We usually respond within an hour, but please be patient. We will get back to you very soon.
Scroll to Top