mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #3541 from pol/docs_withitems_regivar
Create with_items example with a registered var
This commit is contained in:
commit
10bc6f6d9c
1 changed files with 18 additions and 0 deletions
|
@ -800,6 +800,24 @@ The 'register' keyword decides what variable to save a result in. The resulting
|
||||||
- shell: echo "motd contains the word hi"
|
- shell: echo "motd contains the word hi"
|
||||||
when: motd_contents.stdout.find('hi') != -1
|
when: motd_contents.stdout.find('hi') != -1
|
||||||
|
|
||||||
|
As shown previously, the registered variable's string contents are accessible with the 'stdout' method.
|
||||||
|
The registered result can be used in the "with_items" of a task if it is converted into
|
||||||
|
a list (or already is a list) as shown below in another trivial example::
|
||||||
|
|
||||||
|
|
||||||
|
- name: registered variable usage as a with_items list
|
||||||
|
hosts: all
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: retrieve the list of home directories
|
||||||
|
command: ls /home
|
||||||
|
register: home_dirs
|
||||||
|
|
||||||
|
- name: add home dirs to the backup spooler
|
||||||
|
file: path=/mnt/bkspool/{{item}} src=/home/{{ item }} state=link
|
||||||
|
with_items: home_dirs.stdout.split()
|
||||||
|
|
||||||
|
|
||||||
Rolling Updates
|
Rolling Updates
|
||||||
```````````````
|
```````````````
|
||||||
|
|
Loading…
Reference in a new issue