From 103decccac14d0c03e0e5e9dc07e79c222f21407 Mon Sep 17 00:00:00 2001 From: Sam Doooran Date: Fri, 18 Dec 2020 12:08:47 -0500 Subject: [PATCH] Add complex example of fileglob with loop (#72396) * Add complex example of fileglob with loop * Explain Python unpacking notation * Add missing paren --- .../user_guide/complex_data_manipulation.rst | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/docsite/rst/user_guide/complex_data_manipulation.rst b/docs/docsite/rst/user_guide/complex_data_manipulation.rst index d4cddc783b4..4787393d3dd 100644 --- a/docs/docsite/rst/user_guide/complex_data_manipulation.rst +++ b/docs/docsite/rst/user_guide/complex_data_manipulation.rst @@ -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 `_ 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