title: Creating a list of directories with ansible with file module is slow
body: <p>I have a role, that has to create a list of directories. Which directories end up in the list, depends on several conditions that are evaluated at runtime.</p>
  
  <p>When I use the <code>file</code> module, like shown, this is very slow. Creating and even checking for the existence of every directory takes about half a second, which easily sums up to minutes in the scenarios I encounter. </p>
  
  <p>Pipelining is enabled.</p>
  
  <pre><code>- name: Create directories
    file:
      path:   "{{ item }}"
      state:  directory
    with_items:
      - "{{ dirs }}"
    when:
      - dirs is defined
  </code></pre>
  
  <p>A similar question has been asked <a href="https://stackoverflow.com/questions/27985334/why-is-copying-a-directory-with-ansible-so-slow%20[%22here%22]">here</a>, however using <code>synchronize</code> or <code>unarchive</code>, as suggested there, seems very awkward for directories not known in advance, as the directory structure to be synchronized, first has to be created on the local host somewhere.</p>
  
  <p>Are there other alternatives to solve this, I might have missed?</p>
  
  <p>EDIT: 
  I am aware of <code>shell</code> and <code>command</code> and <code>mkdir -p</code> happens to be idempotent. Still I would prefer a way, where ansible manages the state of the directories.</p>