For various reasons/limitations I cannot make new groups in the inventory file and need to use --limit/-l
to specify the hosts.
I was told to do something like:
ansible-playbook -i /path/to/my/inventory/file.ini -l server.1.com server.2.com my-playbook.yml --check --diff
This was throwing an error:
ERROR! the playbook: server.2.com could not be found
From the Ansible Documentation on this subject I found that you could use a separate file to list all the hosts you want to limit. Something like:
ansible-playbook -i /path/to/my/inventory/file.ini -l @list-to-limit.txt my-playbook.yml
However, I need to do it all inline without creating an additional file.
The same Common patters apply to the command-line option
-l
. Quoting the note:For example, given the inventory
and the playbook
The various host's patterns work as expected. For example
Here is how to do it:
I was spacing out and at the time I totally thought I could just list out all the hosts inline and
ansible-playbook
would understand.I fixed my issue by simply adding
-l
before each host name in the command.(I realize this might not be a 'best practice')
My final command looked something like:
ansible-playbook -i /path/to/my/inventory/file.ini -l server.1.com -l server.2.com my-playbook.yml --check --diff