我正在编写简单的两个任务ansible playbook来从Internet下载更新文件并将其推送到托管服务器,类似于:
- hosts: all
serial: 10
tasks:
- name: Download update file
get_url: url=http://f.q.d.n/path/to/file dest=/tmp/
connection: local
run_once: true
- name: Copy update file to all servers
copy: src=/tmp/file dest=/path/to/file mode="..."
第一个任务应该只在localhost上运行一次,其余的在10个串行批次中运行 . 但是根据ansible文档,标记为"run_once"的任务将在每个序列批次中的一个主机上运行 .
我无法使用文档中提到的解决方法,在条件中使用inventory_hostname,因为实际的目标主机可能不同,例如受限制 - 限制等
什么是设计这个剧本的正确方法? pre_task在这里有用吗?
1 回答