Reputation: 543
I'm new to Dynamic Inventory with Ansible.
I have a playbook:
hosts: tag_Name_abc
Running this playbook does what it needs to correctly on the tagged EC2 instance. When I try to use host_vars
I get fatal: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'test_var' is undefined"}
There is a file host_vars/tag_Name_abc
files under the playbook file directory with contents test_var: test_value
, but it's not picking up the variable.
Launching the playbook ansible-playbook -i ec2.py myplaybook.yml
Any advise would be great. Thanks!
Upvotes: 2
Views: 3760
Reputation: 68269
Dynamic inventory script ec2.py
make groups with names tag_key_value
.
To set inventory variables for groups, you should put them into group_vars
folder.
host_vars
is for host-level vars.
In your case, you should use group_vars/tag_Name_abc
file.
Upvotes: 7