【问题标题】:Ansible playbook with serial > 1 and run_once串行 > 1 和 run_once 的 Ansible 剧本
【发布时间】:2016-10-01 15:14:12
【问题描述】:

我正在编写简单的两个任务 ansible playbook 从互联网下载更新文件并将其推送到托管服务器,类似于:

- 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,因为实际的目标主机可能是不同的,例如受 --limit 等限制。
设计这个剧本的正确方法是什么? pre_task 在这里有用吗?

【问题讨论】:

    标签: ansible


    【解决方案1】:
    - hosts: localhost
    
      tasks:
      - name: Download update file
        get_url: url=http://f.q.d.n/path/to/file dest=/tmp/
    
    
    - hosts: all
      serial: 10
    
      tasks:
      - name: Copy update file to all servers
        copy: src=/tmp/file dest=/path/to/file mode="..."
    

    【讨论】:

    • 谢谢!这按预期工作,我不知道即使使用 --limit 执行 playbook,ansible 仍将匹配 localhost 任务
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多