ChatOps – Ansible gets status from router, notifies Slack channel


Just a teaser of the idea that i’m toying with while i’m still working hard on the automation post. The idea of chatops is that your automation scripts should send status notifications (or any other notifications) to a common workspace, such as Slack. I would love to see daily statuses of my routers in my slack channel:
R1: ok
R2: ok
R3: nok

The other direction is also possible (oh the chaos an attacker could wreak upon the network with this one) : it is possible to actually run scripts from Slack.

For now i’ve just registered my slack account, created an app, and ran a test curl command from my VM to the slack channel. I’ll try to built a slack notification into my ansible scripts now.


Obviously I couldn’t leave this at this unfinished stage 😀 I took my ansible playbook and modified it:

- name: add_entry_to_acl 
  hosts: testrouter
   - name: add_new_entry
     - "{{ acl20 }}" 
     parents: ip access-list extended permit_www
     before: ip access-list extended permit_www 
     save_when: modified
   - name: send notification to Slack
     module: slack
     token: <here enter your slack webhook token>
     channel: "#things"
     msg: "Name of the host is {{ ansible_net_hostname }} and the software version is {{ ansible_net_version }} while the platform is {{ ansible_net_model }}"


tode@ubuntu:~/ansiblefolder$ ansible-playbook aclplaybook.yml

PLAY [add_entry_to_acl] ********************************************************

TASK [Gathering Facts] *********************************************************
[WARNING]: Ignoring timeout(10) for ios_facts
[WARNING]: default value for `gather_subset` will be changed to `min` from
`!config` v2.11 onwards
ok: [testrouter]

TASK [add_new_entry] ***********************************************************
changed: [testrouter]

TASK [show clock] **************************************************************
ok: [testrouter]

TASK [send notification to Slack] **********************************************
ok: [testrouter -> localhost]

PLAY RECAP *********************************************************************
testrouter : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


and voila:




Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:


Komentujesz korzystając z konta Wyloguj /  Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj /  Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj /  Zmień )

Połączenie z %s

%d blogerów lubi to: