I have a playbook to restore data from a backup. This is a destructive operation that can potentially run on hosts: all. So currently my playbook has hosts: all in it.
I'd like to force the user to specify the hosts it wants to restore the backup for so that if the playbook is run without --limit option it doesn't work.
Is there any way to protect a playbook so that you have to manually specify which hosts to target as opposed to all?
Sure.
Just write in your playbook (example.yml)
---
- name: Limited playbook
hosts: "{{ target }}"
tasks:
- debug:
msg: "Running on {{ inventory_hostname }}"
Running the playbook would be like
ansible example.yml -e target=host1
You can also add a default value for target if you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With