Set forks for one task in ansible playbook

后端 未结 4 401
一个人的身影
一个人的身影 2021-01-12 17:20

I have one task in my playbook that I want to run on only one host at a time. The rest of the tasks I want to honor the --forks option. Is this possible?

4条回答
  •  花落未央
    2021-01-12 18:01

    Yes, this possible by using the throttle keyword:

    Limit number of concurrent task runs on task, block and playbook level. This is independent of the forks and serial settings, but cannot be set higher than those limits. For example, if forks is set to 10 and the throttle is set to 15, at most 10 hosts will be operated on in parallel.

    Example:

    ---
    
    - hosts: all
      tasks:
          - name: wait in parallel
            command: sleep 20
          - name: wait  in serial
            command: sleep 30
            throttle: 1
    

    The throttle keyword is available in Ansible since version 2.9.

提交回复
热议问题