Ansible: ease your config-job
Deploy same config on multiple boxes with just one shot!
Akhmad Zaimi – IP Netop Manager
Telekomunikasi Indonesia International (TELIN)
Requirement
• Software:
• Python 2.7
• ansible
• Roles:
 Juniper.junos
• Port Enable on network: Netconf
Lets learn YAML
• Start with --- end with …
• Member of list are lines beginning at the same indentation level starting with a "- " (a
dash and a space), example:
Fruits:
- apple
- orange
• Dictionary represented with simple key: value form
Martin:
name: Akhmad Zaimi
job: engineer
• List and Dictionary in other format:
---
martin: {name: Martin D'vloper, job: Developer, skill: Elite}
fruits: ['Apple', 'Orange', 'Strawberry', 'Mango']
Work Environment
• Platform on tested: Juniper router and switches
• List target hosts on /etc/ansible/hosts
• Roles saved in /etc/ansible/roles/
• Run on CLI:
• Ansible-playbook junos-install-config.yml
• Further, Ansible uses “{{ var }}” for variables. If a
value after a colon starts with a “{”, YAML will think it
is a dictionary, so you must quote it, like so:
/etc/ansible/hosts
Sample playbook
• Name file: junos-install-config.yml
---
- name: Load merge a configuration to a device running Junos OS
hosts: switches
roles:
- Juniper.junos
connection: local
gather_facts: yes
vars_prompt:
- name: USRNM
prompt: u
private: no
- name: PWOD
prompt: p
private: no
# - name: HOSTS
# prompt: h
# private: no
tasks:
- name: Checking NETCONF connectivity
wait_for: host={{ inventory_hostname }} port=830 timeout=5
- name: Retrieve info from Junos device
junos_install_config:
host: "{{ inventory_hostname }}"
# host: "{{ HOSTS }}"
user: "{{ USRNM }}"
passwd: "{{ PWOD }}"
logfile: junos-install-config.log
savedir : "/home/user1/ansible-pb/config/"
comment: "add remote backup to ssh server"
#confirm: 0
replace: 1
overwrite: 0
diffs_file: "/home/user1/ansible-pb/config/{{
inventory_hostname }}.diff"
file: /home/user1/ansible-pb/tmp_config/junos-sw-
archive-remote.conf
Sample: Junos config to be added
• Purpose: auto backup config after committing configuration on
remote server
Lets run it!
Recap:
- Open connection success –
authentication success
- Success
Sample: Config changes diff
• Purpose: to log any diff between old and new config change
• Help during network audit!
• Junos also has feature to track last 50 changes!
Sample: Script Log
• Purpose: to log the script process

Ansible with-junos

  • 1.
    Ansible: ease yourconfig-job Deploy same config on multiple boxes with just one shot! Akhmad Zaimi – IP Netop Manager Telekomunikasi Indonesia International (TELIN)
  • 2.
    Requirement • Software: • Python2.7 • ansible • Roles:  Juniper.junos • Port Enable on network: Netconf
  • 3.
    Lets learn YAML •Start with --- end with … • Member of list are lines beginning at the same indentation level starting with a "- " (a dash and a space), example: Fruits: - apple - orange • Dictionary represented with simple key: value form Martin: name: Akhmad Zaimi job: engineer • List and Dictionary in other format: --- martin: {name: Martin D'vloper, job: Developer, skill: Elite} fruits: ['Apple', 'Orange', 'Strawberry', 'Mango']
  • 4.
    Work Environment • Platformon tested: Juniper router and switches • List target hosts on /etc/ansible/hosts • Roles saved in /etc/ansible/roles/ • Run on CLI: • Ansible-playbook junos-install-config.yml • Further, Ansible uses “{{ var }}” for variables. If a value after a colon starts with a “{”, YAML will think it is a dictionary, so you must quote it, like so: /etc/ansible/hosts
  • 5.
    Sample playbook • Namefile: junos-install-config.yml --- - name: Load merge a configuration to a device running Junos OS hosts: switches roles: - Juniper.junos connection: local gather_facts: yes vars_prompt: - name: USRNM prompt: u private: no - name: PWOD prompt: p private: no # - name: HOSTS # prompt: h # private: no tasks: - name: Checking NETCONF connectivity wait_for: host={{ inventory_hostname }} port=830 timeout=5 - name: Retrieve info from Junos device junos_install_config: host: "{{ inventory_hostname }}" # host: "{{ HOSTS }}" user: "{{ USRNM }}" passwd: "{{ PWOD }}" logfile: junos-install-config.log savedir : "/home/user1/ansible-pb/config/" comment: "add remote backup to ssh server" #confirm: 0 replace: 1 overwrite: 0 diffs_file: "/home/user1/ansible-pb/config/{{ inventory_hostname }}.diff" file: /home/user1/ansible-pb/tmp_config/junos-sw- archive-remote.conf
  • 6.
    Sample: Junos configto be added • Purpose: auto backup config after committing configuration on remote server
  • 7.
    Lets run it! Recap: -Open connection success – authentication success - Success
  • 8.
    Sample: Config changesdiff • Purpose: to log any diff between old and new config change • Help during network audit! • Junos also has feature to track last 50 changes!
  • 9.
    Sample: Script Log •Purpose: to log the script process