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:
- get_url: url="some-url/{{item}}" dest="/tmp/{{item}}"
with_items:
- "file1.sh"
- "file2.sh"
- shell: /tmp/{{item}} >> somelog.txt
with_items:
- "file1.sh"
- "file2.sh"
Is there some syntax to avoid the repetition of the item-list?
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 is a request to make with_items applicable to block, but it is still not implemented.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0
with attribution required.
rev 2020.1.3.35708