New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localhost is ignored when using dynamic inventory with --limit localhost #38221
Comments
I'm not sure if this is a bug or not. The current implementation of Implicit localhost (http://docs.ansible.com/ansible/devel/inventory/implicit_localhost.html) is created just in time during playbook execution as referenced if localhost does not exist in the inventory. Due to this, the creation of implicit localhost, happens long after inventory has been parsed and the limit applied to the inventory. I am leaning toward this not being a bug. |
I find this behaviour confusing from the user's perspective. Please consider the following use case based on the example playbook, provided in the original post. The first play In case I want to create and provision
Maybe technically this behaviour is correct, but I believe the focus here should be on the user's perspective. The latter, in my opinion, could benefit from improved consistency. |
cc @bcoca thoughts here? I'm leaning perhaps more towards a docs update to mention that |
The error is not cause of limit not matching an existing host, that would be a warning:
The issue is that once the limit is applied, the play selection doesn't match any hosts (we might want better wording on error here). It seems to work as expected, if localhost is in inventory, no hosts are matched, if the localhost is 'implicit', we create it on demand and ignore inventory restrictions as they don't apply to the 'magical host' we just created. |
I've worked extensively with dynamic inventory in AWS and have gotten to all work together in one playbook - launch instances and then, based on group membership, run plays on instances. First, use a variable to set the pattern to match in 'hosts:', not hard coding it to 'all' and then adding the pattern to '--limit'. You'll need the pattern in more places than just 'hosts:'.
I believe the real issue you're having is that once you get the instances started, the rest of the playbook doesn't know about them. The issue here is that whatever inventory you declared on the command line is sourced into memory at the beginning of the ansible-playbook and never re-read. You have to update the in-memory inventory if you add hosts: So, somewhere in your 'Play 1', you need something like this:
|
interestingly in same scenario ansible doesnet gives any error ping command without any host match
ping command with host match
|
The issue here is that the As such, this is not a bug but expected behavior, and we'll close this issue now. If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
ISSUE TYPE
COMPONENT NAME
limit
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
SUMMARY
I have a playbook with two plays:
The following command behaves differently depending on what is returned by the dynamic inventory :
ansible-playbook -i dynamic_inventory --list-hosts --limit=localhost
Where
dynamic_inventory
is a dynamic inventory script. Namely, openstack.py executed against Rackspace environent (not officially supported I believe).If the dynamic inventory is empty, I get a match:
If the dynamic inventory is NOT empty, then I receive the following error:
ERROR! Specified hosts and/or --limit does not match any hosts
It is not possible to limit the execution to
localhost
when the inventory is not empty.I think the behaviour should be consistent and
localhost
treated as a first-class citizen.STEPS TO REPRODUCE
Run
ansible-playbook -i dynamic_inventory --list-hosts --limit=localhost
. I do not have a static inventory to test the behaviour. The simples caseansible-playbook -i localhost, example.yml --limit localhost --list-hosts
does work.EXPECTED RESULTS
Regardless of the dynamic inventory result,
ansible-playbook -i dynamic_inventory --list-hosts --limit=localhost
should return a match:ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: