summaryrefslogtreecommitdiff
path: root/bin/ansible-playbook
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-01-19 13:39:45 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2015-01-19 13:39:45 -0800
commit2e0472e03bae5535999a34377862fc4b142f4d54 (patch)
tree8000f8e8e5ae26114897754ae0890cb2ffe22270 /bin/ansible-playbook
parentcf6f05e71debedef66289f1951668b1e793576f6 (diff)
downloadansible-2e0472e03bae5535999a34377862fc4b142f4d54.tar.gz
Allow ansible-playbook to determine if an invalid limit is specified
Diffstat (limited to 'bin/ansible-playbook')
-rwxr-xr-xbin/ansible-playbook18
1 files changed, 16 insertions, 2 deletions
diff --git a/bin/ansible-playbook b/bin/ansible-playbook
index 03ca513c12..6390bcba83 100755
--- a/bin/ansible-playbook
+++ b/bin/ansible-playbook
@@ -166,9 +166,23 @@ def main(args):
raise errors.AnsibleError("the playbook: %s does not appear to be a file" % playbook)
inventory = ansible.inventory.Inventory(options.inventory, vault_password=vault_pass)
- inventory.subset(options.subset)
+
+ # Note: slightly wrong, this is written so that implicit localhost
+ # (which is not returned in list_hosts()) is taken into account for
+ # warning if inventory is empty. But it can't be taken into account for
+ # checking if limit doesn't match any hosts. Instead we don't worry about
+ # limit if only implicit localhost was in inventory to start with.
+ #
+ # Fix this in v2
+ no_hosts = False
if len(inventory.list_hosts()) == 0:
- utils.warning("provided hosts list is empty")
+ # Empty inventory
+ utils.warning("provided hosts list is empty, only localhost is available")
+ no_hosts = True
+ inventory.subset(options.subset)
+ if len(inventory.list_hosts()) == 0 and no_hosts is False:
+ # Invalid limit
+ raise errors.AnsibleError("Specified --limit does not match any hosts")
# run all playbooks specified on the command line
for playbook in args: