ansible-documentation icon indicating copy to clipboard operation
ansible-documentation copied to clipboard

Prevent users of a playbook from mistakenly run the plays against their entire inventory

Open Tronde opened this issue 7 months ago • 3 comments

URL of documentation section: https://docs.ansible.com/ansible/latest/dev_guide/developing_collections_structure.html#playbooks-directory

Current content

Hosts: The host should be defined as a variable so the users of a playbook do not mistakenly run the plays against their entire inventory (if the host is set to all). For example - hosts: '{{target|default("all")}}'.

Issue with this content

The value for the host key should be defined as a variable, so the users of a playbook do not mistakenly run the plays against their entire inventory. But the given example hosts: '{{target|default("all")}}' won't prevent this as it specifies all as the default value. When users run this playbook without specifying extra vars or using the --limit option it would do the same harm and run against all hosts from the user's inventory.

How to improve this?

I'm not sure how to improve it. If I were, I would have sent a pull request. But here is an idea for discussion.

Wouldn't it be better to use just the variable {{ target }} and fail if it is not defined? This way it would be a failsafe and prevents harm.

What do you think?

Tronde avatar Jul 12 '24 19:07 Tronde