ansible定义一个task在控制上执行并且要在操作完所有远程机后执行
您可以使用Ansible的local_action模块来在控制机上执行任务,并在操作完所有远程机后执行。以下是一个示例Playbook:
---
- name: Execute task on control machine after all remote hosts
hosts: all
tasks:
- name: Task on remote hosts
# Your tasks on remote hosts here
- name: Task on control machine
local_action:
module: shell
cmd: echo "Task on control machine"
在上面的示例中,Task on remote hosts是您要在远程机上执行的任务。然后,Task on control machine是您要在控制机上执行的任务。
当Ansible执行Playbook时,它会按照顺序执行任务。因此,先执行远程机上的任务,然后再执行控制机上的任务。
请注意,local_action模块中的module参数指定要执行的模块,cmd参数定义要在控制机上执行的命令。您可以根据需要更改这些参数
原文地址: https://www.cveoy.top/t/topic/iedA 著作权归作者所有。请勿转载和采集!