Update example syntax in playbooks_conditionals.rst (#35673)
parent
6c1a63dd14
commit
203c8f4334
|
@ -256,7 +256,9 @@ The following construct selects the first available file appropriate for the var
|
||||||
The following example shows how to template out a configuration file that was very different between, say, CentOS and Debian::
|
The following example shows how to template out a configuration file that was very different between, say, CentOS and Debian::
|
||||||
|
|
||||||
- name: template a file
|
- name: template a file
|
||||||
template: src={{ item }} dest=/etc/myapp/foo.conf
|
template:
|
||||||
|
src: "{{ item }}"
|
||||||
|
dest: /etc/myapp/foo.conf
|
||||||
loop: "{{lookup('first_found', { 'files': myfiles, 'paths': mypaths})}}"
|
loop: "{{lookup('first_found', { 'files': myfiles, 'paths': mypaths})}}"
|
||||||
vars:
|
vars:
|
||||||
myfiles:
|
myfiles:
|
||||||
|
@ -294,14 +296,18 @@ fields::
|
||||||
hosts: all
|
hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: retrieve the list of home directories
|
- name: retrieve the list of home directories
|
||||||
command: ls /home
|
command: ls /home
|
||||||
register: home_dirs
|
register: home_dirs
|
||||||
|
|
||||||
|
- name: add home dirs to the backup spooler
|
||||||
|
file:
|
||||||
|
path: /mnt/bkspool/{{ item }}
|
||||||
|
src: /home/{{ item }}
|
||||||
|
state: link
|
||||||
|
loop: "{{ home_dirs.stdout_lines }}"
|
||||||
|
# same as loop: "{{ home_dirs.stdout.split() }}"
|
||||||
|
|
||||||
- name: add home dirs to the backup spooler
|
|
||||||
file: path=/mnt/bkspool/{{ item }} src=/home/{{ item }} state=link
|
|
||||||
loop: "{{ home_dirs.stdout_lines }}"
|
|
||||||
# same as loop: "{{ home_dirs.stdout.split() }}"
|
|
||||||
|
|
||||||
As shown previously, the registered variable's string contents are accessible with the 'stdout' value.
|
As shown previously, the registered variable's string contents are accessible with the 'stdout' value.
|
||||||
You may check the registered variable's string contents for emptiness::
|
You may check the registered variable's string contents for emptiness::
|
||||||
|
@ -316,7 +322,8 @@ You may check the registered variable's string contents for emptiness::
|
||||||
register: contents
|
register: contents
|
||||||
|
|
||||||
- name: check contents for emptiness
|
- name: check contents for emptiness
|
||||||
debug: msg="Directory is empty"
|
debug:
|
||||||
|
msg: "Directory is empty"
|
||||||
when: contents.stdout == ""
|
when: contents.stdout == ""
|
||||||
|
|
||||||
Commonly Used Facts
|
Commonly Used Facts
|
||||||
|
|
Loading…
Reference in New Issue