Add complex example of fileglob with loop (#72396)

* Add complex example of fileglob with loop

* Explain Python unpacking notation

* Add missing paren
This commit is contained in:
Sam Doooran 2020-12-18 12:08:47 -05:00 committed by GitHub
parent 97765f4ebd
commit 103decccac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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