title: Ansible Looping over list of directories and subdirectories with relative paths
body: <p>How do I loop over a list of directories and subdirectories with relative paths in Ansible?</p>
  
  <p>I tried to loop the processes of creating folders by reusing found paths as variables later on in the program. </p>
  
  <p>This is for creating a list of every directory in one directory:</p>
  
  <pre><code>- find:
        paths: /usr/local/foo/bar/
        recurse: no
        file_type: directory
        register: find_result
  </code></pre>
  
  <p>I wanted this to create a list of every folder in /bar/</p>
  
  <p>Every subfolder in /bar/ contains a subfolder named alice, bob, or charlie. For example:</p>
  
  <p>/usr/local/foo/bar/www/alice</p>
  
  <p>/usr/local/foo/bar/ww2/bob</p>
  
  <p>/usr/local/foo/bar/ww3/charlie</p>
  
  <p>I created a list for the folder names:</p>
  
  <pre><code>FolderTypes:
  
  source: {
  
     - alice
  
     - bob
  
     - charlie
  
  </code></pre>
  
  <p>This is for looping over every alice, bob, or charlie and creating an 'example' folder if it doesn't exist already:</p>
  
  <pre><code>  - file:
  
        path: {{ item.path }}/{{ item.value }}/example
  
        state: directory
  
        owner: user
  
        group: user
  
    -  with_items:
  
        - "{{ find_result.directory }}"
  
        - "{{ items.FolderTypes }}"
  </code></pre>
  
  <p>The program is intended to save found paths, loop through them, and create folders in their subdirectories. I get an error when i try to check the syntax:</p>
  
  <pre><code>ERROR! Syntax Error while loading YAML.
    did not find expected key
  
  The offending line appears to be:
  
    - file:
        path: {{ item.path }}/{{ item.value }}/example
  
                             ^ here
  We could be wrong, but this one looks like it might be an issue with
  missing quotes. Always quote template expression brackets when they
  start a value. For instance:
  
      with_items:
        - {{ foo }}
  
  Should be written as:
  
      with_items:
        - "{{ foo }}"
  </code></pre>