I am porting some automation scripts that used ansible with static inventories to use dynamic inventory (we have a AWS Cloudformation stack per environment and it seems silly to update static files every time we re-create a stack).
There is a single master node per stack and a bunch of worker nodes. To discriminate between master or workers in the playbooks I am using a custom tag (e.g. tag_node_type_master
or tag_node_type_worker
) as the host group (and using --limit tag_env_XXX
to restrict to one specific environment).
The problem comes when I need to let the worker nodes know which is their master node. Currently there is a template that references a statically defined variable with the private DNS name of the master node, and that's not an acceptable option anymore.
I am trying to do something in the vars section like master_node: {{tag_node_type_master[0]}}
(pick the first, and only, element of that hosts group), but that does not work (it says that the variable is undefined, which makes sense because it's not a variable but a hosts group).