
上QQ阅读APP看书,第一时间看更新
How to do it...
In the inventory file, we define hosts and we group the hosts into groups. We now define two directories that Ansible searches for group variables and host variables:
- Create two folders, group_vars and host_vars:
$ cd ch1_ansible
$ mkdir group_vars host_vars
- Create ios.yml and junos.yml files inside group_vars:
$ touch group_vars/cisco.yml group_vars/juniper.yml
- Create mx1.yml and csr1.yml inside host_vars:
$ touch host_vars/csr1.yml host_vars/mx1.yml
- Populate variables in all the files, as shown here:
$echo 'hostname: core-mx1' >> host_vars/mx1.yml
$echo 'hostname: core-mx2' >> host_vars/mx2.yml
$echo 'hostname: edge-csr1' >> host_vars/csr1.yml
$echo 'hostname: edge-csr2' >> host_vars/csr2.yml
$echo 'os: ios' >> group_vars/cisco.yml
$echo 'os: junos' >> group_vars/juniper.yml