On Wed, 29 Apr 2020 at 11:01, Momodou Fatty <
modl...@gmail.com> wrote:
>
> Dick what I meant by "it will be a bit too much" is that I have over 100 hosts, and it will only increase. Do I really want to create a file for each of these hosts in the host_vars directory?
> This does not seem like it will scale well. 1000 hosts means 1000 files in host_vars directory.
>
> Considering I have over 100 hosts, each with it's own host-specific variables/values. And I need to use these variables/values in my jinja template to render a config for each host.
> You being the expert here, how do you think I should approach this?
> - Create yaml files for each of the 100 hosts in /etc/ansible/host_vars. ( host_vars/host1, host2 ...host100)
> - Inside of my hosts file in /etc/ansible/hosts.yaml/ini, for each host in hosts, define variables/values for each host (I could use the hosts.ini too)
^^
This is the preferred choice in your case. To be clear, this is the
"defining host variable in the inventory" approach.
And because those variables are nested/complex, it's probably best to
use a single YAML style inventory file.
This is what it would be looking like:
dnmvisser@NUC8i5BEK ~$ cat inventory.yml
---
junos:
10.10.10.10:
hostname: hostname1
data_nexthop: 100.12.1.7
interfaces:
mgmt_interface:
name: em0
ip: 10.10.10.10
subnet: 31
data_interface:
name: et-0/0/3
ip: 100.12.1.6
subnet: 31
tor_name: seattle_router_01
10.10.10.11:
hostname: hostname2
data_nexthop: 100.12.1.98
interfaces:
mgmt_interface:
name: em0
ip: 10.10.10.11
subnet: 54
data_interface:
name: et-0/0/2
ip: 100.12.1.7
subnet: 99
tor_name: seattle_router_02
10.10.10.12:
hostname: hostname3
data_nexthop: 100.12.65.234
interfaces:
mgmt_interface:
name: em0
ip: 10.10.10.12
subnet: 32
data_interface:
name: et-0/0/9
ip: 100.12.11.97
subnet: 19
tor_name: seattle_router_04
You can then simply do:
ansible-playbook -i inventory.yml ....
Since everything is defined in this single file, you can remove all
the files below host_vars, or even better remove the entire host_vars
directory (if there is nothing in there).