How can I run a single task from an Ansible playbook and the handler that gets notified when that task completes successfully, while skipping all other tasks in the relevant playbook?
Currently I execute the following:
ansible-playbook --start-at-task "task1" --step -K -i hosts playbook.yml
and then press Ctrl+c after the task has finished. This will also skip the handler however.
I know I can add a tag to the task and use that, as in How to run only one task in ansible playbook?, but I would prefer being able to do this without adding a tag. Is that possible?
It is possible to run a separate role (from roles/
dir):
ansible -i stage.yml -m include_role -a name=create-os-user localhost
and a separate task file:
ansible -i stage.yml -m include_tasks -a file=tasks/create-os-user.yml localhost
If you externalize tasks from role to root tasks/
directory (reuse is achieved by import_tasks: ../../../tasks/create-os-user.yml
) you can run it independently from playbook/role.
There's currently nothing coming with ansible-playbook to allow you to run a single task, like --task
. Thus, to me, the tag along with the --tags
option is your best solution here.
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