Using Ansible to deploy Juniper configurations

Ansible_plus_JuniperAutomation is a growing technology in enterprise IT departments.  The ability to automate hundreds of steps for developing, building, deploying, and scaling applications and servers is a huge win for many of our fellow engineers.  Both DevOps and SysOps are loving the new power that it brings.  But, what about NetOps?  Is there any love there?  Well, there is now, thanks to a few developers at Juniper Networks, Ansible, and others.

In this video, I will show you how to deploy a configuration to Junos devices using Ansible.  The configuration is just a simple single-line configuration, but I kept it simple for brevity only.  The configuration could be as complex as you need it to be.

There are a few simple requirements to be fulfilled on your Ansible Control system.

$ sudo pip install ncclient
$ sudo pip install junos-eznc
$ sudo ansible-galaxy install Juniper.junos

You also need to have NETCONF enabled on your Juniper devices:

# set system services netconf ssh

Once that’s done, you can start pushing configurations, deploying software, and writing your Ansible Playbooks to your hearts desire!  Here is the playbook that I created for the example:

---
- hosts: lab_juniper_ro
  roles:
  - Juniper.junos
  connection: local
  gather_facts: no

  - name:  Deploy NTP Server
    junos_install_config:
      host={{inventory_hostname}}
      user=aaron.paxson
      file=resources/config-user.set
      overwrite=false
      logfile=logs/deploy-user.log

See below the video for reference material, documentation, and guides.

Useful links for more information:

Share This Page : Share on TwitterShare on FacebookShare on GooglePlusShare on PinterestShare on Linkedin
  • Geert Van Daal

    So you still need to enable netconf before doing config roll outs? Doesn’t this contradict rolling out configs to out-of-the-box switches?

    • http://www.myteneo.net Aaron Paxson

      Sorry, Geert. I think I have a problem with my notifications. I didn’t see this comment. You would use NetConf after the switch has been provisioned. Before it’s provisioned, you would use junos-netconify to access the console to enable netconf, and then deploy.

  • RaviCharan

    Hi Aron,

    This is very informative and helpful. I am trying to connect to a Juniper host from my Ansible machine, I am unable to establish connection between them. I did not create ssh key pairs, instead I have included the password in inventory file.

    Juniper ansible_host=192.168.32.110 ansible_connection=ssh ansible_user=root ansible_ssh_pass=admin