From 203c8f433497add4f32dc446ac6368da1c0ac8a2 Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Sat, 3 Feb 2018 06:29:22 -0500 Subject: [PATCH] Update example syntax in playbooks_conditionals.rst (#35673) --- docs/docsite/rst/playbooks_conditionals.rst | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/docsite/rst/playbooks_conditionals.rst b/docs/docsite/rst/playbooks_conditionals.rst index af429183d23..ed567735219 100644 --- a/docs/docsite/rst/playbooks_conditionals.rst +++ b/docs/docsite/rst/playbooks_conditionals.rst @@ -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:: - 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})}}" vars: myfiles: @@ -294,14 +296,18 @@ fields:: hosts: all tasks: - - name: retrieve the list of home directories - command: ls /home - register: home_dirs + - 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 + 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. 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 - name: check contents for emptiness - debug: msg="Directory is empty" + debug: + msg: "Directory is empty" when: contents.stdout == "" Commonly Used Facts