Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Update the group_vars/all.yml file with the following parameters to define the various system-level parameters such as dns and system users, as shown in the following code:
$ cat group_vars/all.yml
tmp_dir: ./tmp
config_dir: ./configs
global:
dns:
- 172.20.1.1
- 172.20.1.15
root_pwd: $1$ciI4raxU$XfCVzABJKdALim0aWVMql0
users:
- role: super-user
SSH_key: Ansible_SSH_key.pub
username: admin
- hash: $1$mR940Z9C$ipX9sLKTRDeljQXvWFfJm1
passwd: 14161C180506262E757A60
role: super-user
username: Ansible
  1. Create a new playbook called pb_jnpr_basic_config.yml with the following tasks, to set up dns, hostname and system users on Juniper devices:
$ cat pb_jnpr_basic_config.yml
---
- name: Configure Juniper Devices
hosts: junos
tasks:
- name: "Conifgure Basic System config"
junos_system:
hostname: "{{ inventory_hostname }}"
name_servers: "{{ global.dns }}"
state: present
- name: "Configure Users"
junos_user:
name: "{{ item.username }}"
role: "{{ item.role }}"
SSHkey: "{{ lookup ('file', item.SSH_key) }}"
state: present
with_items: "{{ global.users | selectattr('SSH_key','defined') | list }}"