Apply with_items on multiple tasks

后端 未结 2 491
醉话见心
醉话见心 2021-01-03 20:19

Is it possible to apply a list of items to multiple tasks in an Ansible playbook? To give an example:

- name: download and execute
  hosts: server1
  tasks:
         


        
2条回答
  •  长情又很酷
    2021-01-03 20:46

    As of today you can use with_items with include, so you'd need to split your playbook into two files:

    - name: download and execute
      hosts: server1
      tasks:
      - include: subtasks.yml file={{item}}
        with_items:
        - "file1.sh"
        - "file2.sh"
    

    and subtasks.yml:

    - get_url: url="some-url/{{file}}" dest="/tmp/{{file}}"
    - shell: /tmp/{{file}} >> somelog.txt
    

    There was a request to make with_items applicable to block, but the Ansible team has said it will never be supported.

提交回复
热议问题