One loop over multiple Ansible tasks

后端 未结 3 1516
面向向阳花
面向向阳花 2020-12-29 03:49

I\'ve created an Ansible playbook that creates a cloud instance and then installs some programs on the instance. I want to run this playbook multiple times (without using a

3条回答
  •  孤独总比滥情好
    2020-12-29 04:15

    I managed to do this by recursively including the same yaml file based on a condition. Here is the gist: https://gist.github.com/ParagDoke/5ddfc3d5647ce9b0110d1b9790090092. Effectively, in your playbook, include a file with some vars:

      - name: Invoke poller
        vars:
          some_condition: '"failed" not in response.content and response.json.status=="running"'
        include_tasks: status-poller.yml
    

    Then in status-poller.yml, include itself:

    - include_tasks: includes/status-poller.yml
      when: some_condition
    

提交回复
热议问题