diff options
author | Lars Kellogg-Stedman <lars@redhat.com> | 2015-10-28 16:45:12 -0400 |
---|---|---|
committer | Lars Kellogg-Stedman <lars@redhat.com> | 2015-10-28 16:56:21 -0400 |
commit | 097adec834368ff0bae2a9829be536355650e198 (patch) | |
tree | ffd095432f3d6601ca0c8af204b408780a8ae713 | |
parent | 299054852a4e93a2e739b968256785e87ff32228 (diff) | |
download | ansible-097adec834368ff0bae2a9829be536355650e198.tar.gz |
add documentation for with_file loops
This commit adds documentation for the `with_file` loop construct,
resolving #7890 and #9160.
-rw-r--r-- | docsite/rst/playbooks_loops.rst | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docsite/rst/playbooks_loops.rst b/docsite/rst/playbooks_loops.rst index fef48ca49a..b25e95941e 100644 --- a/docsite/rst/playbooks_loops.rst +++ b/docsite/rst/playbooks_loops.rst @@ -93,6 +93,35 @@ And you want to print every user's name and phone number. You can loop through .. _looping_over_fileglobs: +Looping over Files +`````````````````` + +``with_file`` iterates over a list of files, setting `item` to the content of each file in sequence. It can be used like this:: + + --- + - hosts: all + + tasks: + + # emit a debug message containing the content of each file. + - debug: + msg: "{{item}}" + with_file: + - first_example_file + - second_example_file + +Assuming that ``first_example_file`` contained the text "hello" and ``second_example_file`` contained the text "world", this would result in:: + + TASK [debug msg={{item}}] ****************************************************** + ok: [localhost] => (item=hello) => { + "item": "hello", + "msg": "hello" + } + ok: [localhost] => (item=world) => { + "item": "world", + "msg": "world" + } + Looping over Fileglobs `````````````````````` |