title: Ansible: How do I avoid registering a variable when a "when" condition is *not* met?
body: <p>I have the following Ansible Playbook code:</p>
  
  <pre><code>- name: Users | Generate password for user (Debian/Ubuntu)
    shell: makepasswd --chars=20
    register: make_password
    when: ansible_distribution in ['Debian', 'Ubuntu']
  
  - name: Users | Generate password for user (Fedora)
    shell: makepasswd -m 20 -M 20
    register: make_password
    when: ansible_distribution in ['Fedora', 'Amazon']
  
  - name: Users | Generate password for user (CentOS)
    shell: mkpasswd -l 20
    register: make_password
    when: ansible_distribution in ['CentOS']
  
  - name: debug
    debug: var=make_password
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>TASK: [users | debug] 
  ok: [127.0.0.1] =&gt; {
                       "var": {
                         "make_password": {
                           "changed": false,
                           "skipped": true
                         }
                       }
                     }
  </code></pre>
  
  <p>... Because every <code>register</code> block gets executed regardless of the <code>when</code> condition.</p>
  
  <p>How would I fix this so <code>make_password</code> doesn't get overwritten when the <code>when</code> condition isn't met?</p>
  
  <p>Or if this is the wrong approach for what you can see that I'm trying to accomplish, let me know of a better one.</p>