Skip to content

chatops for network engineers: slack and hubot and ansible for junos automation

Notifications You must be signed in to change notification settings

rickmur/junos_genius

Repository files navigation

What to find on this repo:

Chatops for network engineers.
Initially inspired by this demo https://www.dravetech.com/blog/2016/03/30/chatops-demo.html
Actually based on slack and hubot and ansible for junos automation

Bot capabilties:

The bot can execute junos commands (set/delete/show) to a device or a group of devices.
It can also backup the junos configuration, rollback the junos configuration, load a jinja2 template, apply a playbook to junos devices.
This is easily extensible.

Syntax:

Here’s the chat syntax to delegate tasks to the bot, with some help:

  • myhubot target <target> set <junos_command> - Execute a junos set command on device/group <target>
  • myhubot target <target> delete <junos_command> - Execute a junos delete command on device/group <target>
  • myhubot target <target> rollback <rb_id> - Rollback <rb_id> the configuration of device/group <target>
  • myhubot target <target> template <template> - Backup the configuration of device/group <target>, and apply the jinja2 template <template> to the device/group <target>
  • myhubot target <target> backup - Backup the configuration of the device/group <target>
  • myhubot target <target> show <junos_command> - Execute a junos show command on device/group <target> and print the command output
  • myhubot target <target> playbook <playbook> - Execute the ansible playbook <playbook> on device/group <target>
  • hubot list playbooks - Print the list of Ansible playbooks
  • hubot list templates - Print the list of Jinja2 templates
  • hubot display - Print an Ansible file (playbook, template, ...)

Note: <target> is a device or a group of devices. <target> has to exist in the ansible inventory file (https://github.com/ksator/chatops_junos/blob/master/ansible/hosts).

Chat examples:
@myhubot help

@myhubot help template
@myhubot list templates
@myhubot display openconfig_bgp.j2
@myhubot list hosts
@myhubot target Openconfig_Routers template openconfig_bgp.j2
@myhubot target FR-MX80-214 show bgp summary 
@myhubot target Openconfig_Routers rollback 1

@myhubot target all backup

@myhubot target MX240-04 set system login message newbanner
@myhubot target MX240-04 delete system login message newbanner

@myhubot list playbooks
@myhubot target FR-MX80-214 playbook pb.check.physical.topology.yml

How does it work:

The bot configuration is this file: https://github.com/ksator/chatops_junos/blob/master/scripts/junos.coffee. This is where we define the various actions the bot has to take based on the slack messages in the chat room. So the bot is configured to execute Ansible playbooks.

The bot uses Ansible under the hood. Here's the Ansible content (playbooks, variables, inventory ....) https://github.com/ksator/chatops_junos/tree/master/ansible

So, as example, the slack message:

myhubot target <target> template <template>    

or

@myhubot target <target> template <template>  

triggers the ansible playbook pb.template.yml with some variable definitions (using the --extra-vars option to pass the variables definition to the playbook):
Actually, the bot will execute this command:

ansible-playbook $PWD/ansible/pb.template.yml --extra-vars = "{'device': <target>, 'template': <template>}"

Which is the equivalent of:

ansible-playbook $PWD/ansible/pb.template.yml --extra-vars "device=<target> template=<template>"  

The steps to reproduce are:

ksator@ubuntu:~/myhubot$ HUBOT_SLACK_TOKEN=xoxb-90946701733-BTJh5QnUdQrTMcbtjgawmvjo ./bin/hubot -a slack

Contributions, bugs, questions, suggestions, enhancement requests

They are more than welcome. Please submit github issues or pull requests.

About

chatops for network engineers: slack and hubot and ansible for junos automation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published