Lately I’ve been using Ansible to update configurations on my JunOS devices. Here’s a fun little script to get you started. It will print the configuration of the DHCP service on a JunOS device, then update the name-server DHCP option to something new. The following playbook uses the JunOS ansible role
Install with “ansible-galaxy install Juniper.junos
”
The structure of your inventory file should be like so —
--- wra: children: juniper: hosts: HOST_NAME: ansible_host: 10.0.30.1 ansible_ssh_pass: your_ssh_pass ansible_network_os: junos ansible_user: root dhcp_pool: 10.0.30.0/24
Here’s the complete playbook. You’ll want to change the “Commit” option to “True” when ready to run. Run with:
sudo ansible-playbook -i your_inventory_file.yaml /path/to/ansible_junos_update_dhcp.yaml