Hi All,
I’m looking for some advice / pointers / ideas on the following situation:
Let me outline what I’ve got / what I’m thinking and then what I’m trying to achieve with that thinking.
My Inventory file has a number of groups, sub-groups, and (obviously) hosts.
I use the FQDN as the inverntory_hostname.
Each group, sub-group, and host has a number of group_vars or host_vars associated with it, and the whole Inventory file is structured in such a way that:
- Only the unique
host_varsfor a host appear in that host’s Var file - Only those
group_varsthat are common to a sub-group’s host(s) (ie unique to that sub-group) appear in that sub-group’s Var file - Only only those
group_varsthat are common to a group’s sub-group(s) and/or host(s) (ie unique to that group) appear in that group’s Var file
The idea here is that (as I understand things - and I could be wrong) the group-vars “cascade down” to the individual hosts and are merged into the set of host_vars.
One of the set of host_vars/group_vars for (VM) hosts are the specifications for that host ie Number of CPUs, RAM, VLAN, IPv4 & IPv6 Addresses, MAC Address(s), etc. I have a “Golden Image” VM set up with the most commonly used (ie default) set of these settings which I currently clone and (as required) modify when I need a new VM - which, to be honest, isn’t all that often.
What I’m thinking is that I can use Ansible to perform the “clone & modify” by providing the playbook with the hostname (or FQDN) of the new soon-to-exist VM and (somehow) how Ansible extract the relevant CPUs, RAM, etc, variables from the Inventory file, even though the actual host won’t exist until the end of the playbook run.
The command to start the playbook would be something like: ansible-playbook -i localhost clone_vm.yml, and inside the play there is a vars_prompt: (say vm_name) asking for the new VM’s hostname (or FQDN).
Is something like this viable (I’d like to think that is would be, as I already have a bash script which does all this - although I’ve got to provide all the values manually when I call the script) and if so, how do I take the vars_prompt: vm_name and use that as a key to lookup the other host_vars specific to the soon-to-be new host (and, of course, the corresponding group_vars in the new host’s sub-group(s) and group)?
Thanks in advance for the help
Cheers
Dulux-Oz