title: Using local facts (`ansible_local`) when they may not exist
body: <p>I'm using ansible for an automated deployment.</p>
  
  <p>The installation of a certain software package I need is a long, non-standard and boring operation. I'd like to run the corresponding tasks only if necessary, that is if it wasn't already executed before.</p>
  
  <p>My plan consists in having the last step of such installation to create a local fact:</p>
  
  <pre><code>- name: Flag installed
    block:
      - file:
          path: /etc/ansible/facts.d
          state: directory
      - copy:
          src: mypackage.fact
          dest: /etc/ansbile/facts.d/mypackage.fact
  </code></pre>
  
  <p>The <code>mypackage.fact</code> file is this:</p>
  
  <pre><code>[general]
  installed=yes
  </code></pre>
  
  <p>At this point I'd like to use such local fact as conditional, so I can avoid running the boring procedure twice:</p>
  
  <pre><code>- include: install_boring
    when: not(ansible_local.mypackage.general.installed | bool)
  </code></pre>
  
  <p>Obviously this fails because <code>ansible_local</code> is not defined. I know the <code>default</code> filter exists, but it feels just unconfortable to do a multi-level default for each of <code>ansible_local</code>, <code>mypackage</code>, <code>general</code> and <code>installed</code>.</p>
  
  <p>Is there an elegant way to achieve this?</p>