Ansible Playbook for Cisco BGP Routing Topology

This is my Ansible Playbook for a simple Cisco BGP routing topology and using a CICD pipeline for integration testing. The virtual network environment is created on-demand by using Vagrant, see my post about Cisco IOSv and XE network simulation using Vagrant.

Network overview:

Here’s my Github repository where you can find the complete Ansible Playbook:

You can find all the variables for the interface and routing configuration under host_vars. Below is an example for router rtr-1:


hostname: rtr-1
domain_name: lab.local


    alias: connection rtr-2

    alias: connection rtr-3

  asn: 65001
    - {address:, remote_as: 65000}
    - {address:, remote_as: 65000}
    - {network:, mask:}
    - {network:, mask:}
    - {network:, mask:}
  maxpath: 2


  • Hostname: The task in main.yml uses the Ansible module ios_system and configures hostname, domain name and disables dns lookups.
  • Interfaces: This role uses the Ansible module ios_config to deploy the template interfaces.j2 to configure the interfaces. In the main.yml is a second task to enable the interfaces when the previous template applied the configuration.
  • Routing: Very similar to the interfaces role and uses also the ios_config module to deploy the template routing.j2 for the BGP routing configuration.

Main Ansible Playbook site.yml:


- hosts: all

  connection: local
  user: vagrant
  gather_facts: 'no'

    - hostname
    - interfaces
    - routing

When a change triggers the gitlab-ci pipeline it spins up the Vagrant instances and executes the main Ansible Playbook:

After the main site.yml ran, a second Playbook is executed for basic connectivity testing cisco_check_icmp.yml. This uses the Ansible module ios_ping and can be useful in my case to validate if the configuration was correctly applied:

If everything goes well, like in this example, the job is successful:

I will continue to improve the Playbook and the CICD pipeline so come back later to check it out.

Leave a comment

Please share!

4 Replies to “Ansible Playbook for Cisco BGP Routing Topology”

  1. Bernd, great article! Very impressed with the end to end content on Ansible and the layout of your website in general. I am starting my own blog soon on automation as I find very few end to end complete walk throughs of Ansible deployments. Thanks for this and keep up the good work,

    Ken Murphy, Senior Network Engineer, Dell EMC

    1. Thank you, glad you like my blog.
      Network automation is a very interesting topic and missing more information on the internet. You should for sure start your own blog, share your link with me when you’re ready.


      1. Hi Bernd, check out my new blog at, my first post is an MPLS lab deployment, inspired by your own Cisco Lab Provisioning with Ansible. Like your own blog I hope to get the interest going in Ansible so that other Network Engineers can benefit from this great automation tool. Happy new year!

        1. Hi Ken,
          Thanks for sharing, I will have a look and try it out 🙂
          Nice to hear that my blog inspired you to start your own. I set up a blogroll and link to your page.
          Happy New Year!

Leave a Reply

Your email address will not be published. Required fields are marked *