Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Return non-zero error code if no hosts match#121

Merged
joshmoore merged 1 commit intoome:masterfrom
manics-archive:no_hosts_match
Sep 29, 2016
Merged

Return non-zero error code if no hosts match#121
joshmoore merged 1 commit intoome:masterfrom
manics-archive:no_hosts_match

Conversation

@manics
Copy link
Copy Markdown
Member

@manics manics commented Sep 23, 2016

This adds a callback so that Ansible will set a non-zero exit code if a playbook was run but no hosts match. This is useful when running ansible-playbook automatically. For example, when running vagrant to test the Vagrantfile if there is a mismatch between the hosts expect by the playbook and the hosts in the Vagrantfile ansible would normally not care.

If you think this is inappropriate it could go into an alternative ansible.cfg which is used only by vagrant (e.g. set ANSIBLE_CONFIG)

This is useful when running ansible-playbook automatically, since failure to mat
ch a host may mean there's an incorrect hostname or groupname somewhere
@joshmoore
Copy link
Copy Markdown
Member

I get:

ERROR! Specified --limit does not match any hosts

even without this PR. In fact, I don't I have yet been able to make it execute.

@manics
Copy link
Copy Markdown
Member Author

manics commented Sep 29, 2016

Run it without --limit, but with a playbook containing - hosts: non-existent-group

The idea is to catch errors in the tests, e.g. in the IDR multinode omero example #124 requires a prefix (idr_environment). If you were to change this but forget to change the prefix on the groups in the Vagrantfile ansible wouldn't match any hosts, but would still exit cleanly.

@joshmoore
Copy link
Copy Markdown
Member

$ /opt/v/bin/ansible-playbook none.yml

PLAY [DNE] *********************************************************************
skipping: no hosts matched

PLAY RECAP *********************************************************************

ERROR: No hosts matched

👍

@joshmoore joshmoore merged commit 5c09758 into ome:master Sep 29, 2016
@manics manics deleted the no_hosts_match branch October 5, 2016 12:04
manics pushed a commit to manics-archive/ome-infrastructure that referenced this pull request Nov 24, 2016
Return non-zero error code if no hosts match
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants