Reputation: 87
my inventory looks like this:
[Databases]
"DB1 - SQL 2012" ansible_host=DB1
"DB2 - SQL 2014" ansible_host=DB2
"DB3 - SQL 2017" ansible_host=DB3
Im using the string in the quotation marks as {{ inventory_hostname }} in multiple tasks for example to perform snapshots in vSphere. Regarding the Ansible documentation in an ini inventory, the first part should be the "alias" not the inventory_hostname, but alias is not working, maybe somebody can explain that aswell.
The bad thing about it is, that i can't limit the playbooks to run on one host:
ansible-playbook test.yml --limit DB1 -->
[WARNING]: Could not match supplied host pattern, ignoring: DB1
ansible-playbook test.yml --limit "DB1 - SQL 2012" -->
Could not match supplied host pattern, ignoring: DB1
Could not match supplied host pattern, ignoring: -
Could not match supplied host pattern, ignoring: SQL
Could not match supplied host pattern, ignoring: 2012
I guess the right setup would be something like:
[Databases]
DB1_SQL-2012 invenvory_hostname="DB1 - SQL 2012" ansible_host=DB1
DB2_SQL-2014 inventory_hostname="DB2 - SQL 2014" ansible_host=DB2
And i would be able to limit with DB1_SQL-2012, but i would like to keep the inventory as clean as possible. Does anyone has an idea how i can limit this to the ansible_host even if there is an alias/inventory_hostname present?
Upvotes: 0
Views: 777
Reputation: 9372
Regardless whether you use separate files or one file as the inventory: You decided to identify a host uniquely with a pattern like "DB1 - SQL 2012"
. Although it looks strange to me that is ok for Ansible.
But now you want to abbreviate, or identify a host by looking at defined variables. This is documented as not working. Check Limitation of Patterns.
Upvotes: 1