【问题标题】:Serial execution of a role in AnsibleAnsible 中角色的串行执行
【发布时间】:2021-02-04 22:52:56
【问题描述】:

我的剧本定义如下:

- name: install percona rpms
  hosts: imdp
  roles:
    - role1
    - role2
    - role3
    - role4

我只希望角色 3 中定义的任务能够串行执行。如果我在 role3 任务中定义serial: 1,它就不起作用。所有任务都是并行执行的。但是如果我在主 yaml(上面的 yaml)中定义了serial: 1,那么所有的角色都是串行执行的,这也是不需要的。

我怎样才能让 role3 连续执行?

【问题讨论】:

    标签: ansible ansible-role


    【解决方案1】:

    serial”仅在剧中可用。见Playbook Keywords。解决方案是将角色分配给更多的戏剧。例如

    - name: Play 1. install percona rpms
      hosts: imdp
      roles:
        - role1
        - role2
    
    - name: Play 2. install percona rpms
      hosts: imdp
      serial: 1
      roles:
        - role3
    
    - name: Play 3. install percona rpms
      hosts: imdp
      roles:
        - role4
    

    【讨论】:

      【解决方案2】:

      As example (emulation)

      我的任务.yml:

      ---
      - include_tasks: custom-tasks.yml
        when: inventory_hostname == item
        with_items: "{{ ansible_play_hosts }}"
      

      自定义任务.yml:

      ---
      - debug:
          var: inventory_hostname
      

      【讨论】:

        猜你喜欢
        • 2022-01-25
        • 2014-01-30
        • 1970-01-01
        • 1970-01-01
        • 2016-11-15
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多