Hi, I want to insert an failure on my playbook where if the hostgroup isnt in the inventory, it fails.
Inventory path is inventory/"environment_name"/inventory and looks similiar to this [NodeGroup1] node1@node [NodeGroup2] node2@node. node3@node. When running a playbook using --extra vars and declaring the name of the host group like so ansible-playbook deploy_rpm.yml -i environment/testEnv --extra-vars='{"hostgroup": "NodeGroup1", "var1": "test-rpm", "version": "0.1"}' It passes as NodeGroup1 is in the inventory When the hostgroup is named wrong, 'NodeGroup999' for example. ansible-playbook deploy_rpm.yml -i environment/testEnv --extra-vars='{"hostgroup": "NodeGroup999", "var1": "test-rpm", "version": "0.1"}' It just silently fails but doesnt return an error message or stop. I have added this in as a task but it doesnt seem to like it. - name: "Grep inventory to check hostgroup exists." fail: msg:="Hostgroup '{{ hostgroup }}' is not defined" when: - inventory_hostname in groups['hostgroup']|default([]) How can i improve this task to stop the playbook and return a failure? Is it best to put the path of the inventory files inside the 'when' part of the task? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1bd5d26b-7722-4c57-b735-086a48d6e8be%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.