Run only one task and handler from ansible playbook

此生再无相见时 提交于 2021-01-01 07:02:06

问题


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?


回答1:


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.




回答2:


It is possible to run separate role (from roles/ dir):

ansible -i stage.yml -m include_role -a name=create-os-user localhost

and 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 ccan run it independently from playbook/role.



来源:https://stackoverflow.com/questions/41281997/run-only-one-task-and-handler-from-ansible-playbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!