title: Ansible Playbook using variable stdout as input to create files
body: <p>I'm creating a playbook to verify all NFS present in fstab are mounted and also they are RW [read/write].</p>
  <p>Here is the first block of my playbook that is actually working.
  Compares the <code>mount</code> output with the current <code>fstab</code>.</p>
  <pre><code>  tasks:
  
      -
        name: Get mounted devices
        shell: /usr/bin/mount | /usr/bin/sed -n {'/nfs / {/#/d;p}'} | /bin/awk '{print $3}'
        register: current_mount
      -
        set_fact:
          block_devices: &quot;{{ current_mount.stdout_lines }}&quot;
  
      -
        shell: /usr/bin/sed -n '/nfs/ {/#/d;p}' /root/testtab | /usr/bin/awk '{print $2}'
        register: fstab
      -
        set_fact:
          fstab_devices: &quot;{{ fstab.stdout_lines }}&quot;
      -
        name: Device not mounted
        fail:
          msg: &quot;ONE OR MORE NFS ARE NOT MOUNTED, PLEASE VERIFY&quot;
        when: block_devices != fstab_devices
  </code></pre>
  <p>Now to verify these are Read/Write ready:</p>
  <ol>
  <li>I need to actually create a file inside the paths stored on <code>{{ current_mount }}</code></li>
  </ol>
  <p>1.1) If it succeed we move forward and delete the newly created files</p>
  <p>1.2) If there is failure when creating one or all the files, we need to fail the playbook and <code>msg</code> which of them is not read/write [that mean, if we can't touch[create] a file inside then the FS then is not RW ]</p>
  <p>I tried to do the below, but it seems that it does not work like that.</p>
  <pre><code>    -
        file:
          path: &quot;{{ current_mount }}&quot;/ansibletestfile
          state: touch
      -
        file:
          path: &quot;{{ current_mount }}&quot;/ansibletestfile
          state: absent
  </code></pre>
  <p>This is a sample of whats inside the <code>{{ current_mount }}</code></p>
  <pre><code>/testnfs
  /testnfs2
  /testnfs3
  </code></pre>
  <p>After doing some research, it seems that to create more than one file within different FS listed in a variable I would have to use the item module, but I had no luck</p>
  <p>Please let me know if there is a way to perform this task.</p>