Add complex example of fileglob with loop (#72396)

* Add complex example of fileglob with loop

* Explain Python unpacking notation

* Add missing paren
pull/73070/head
Sam Doooran 4 years ago committed by GitHub
parent 97765f4ebd
commit 103decccac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -151,6 +151,29 @@ Another way is to avoid adding elements to the list in the first place, so you c
- "bar"
Custom Fileglob Based on a Variable
-----------------------------------
This example uses `Python argument list unpacking <https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists>`_ to create a custom list of fileglobs based on a variable.
.. code-block:: YAML+Jinja
:caption: Using fileglob with a list based on a variable.
- hosts: all
vars:
mygroups
- prod
- web
tasks:
- name: Copy a glob of files based on a list of groups
copy:
src: "{{ item }}"
dest: "/tmp/{{ item }}"
loop: '{{ q("fileglob", *globlist) }}'
vars:
globlist: '{{ mygroups | map("regex_replace", "^(.*)$", "files/\1/*.conf") | list }}'
.. _complex_type_transformations:
Complex Type transformations

Loading…
Cancel
Save