Ansible stat, register and when while looping

ansible

I have this:

   - stat: path=/etc/pki/tls/certs/{{ item.ServerName }}.crt
     with_items:
       - "{{ prod }}"
     register: sslcheck

   - debug: var=sslcheck

   - name: Create self-signed SSL cert
     command: openssl req -new -nodes -x509 -subj "/C=US/ST=Oregon/L=Portland/O=IT/CN=${item.ServerName}" -days 3650 -keyout /etc/pki/tls/private/{{item.ServerName}}.key -out /etc/pki/tls/certs/{{item.ServerName}}.crt -extensions v3_ca creates=/etc/pki/tls/certs/{{item.ServerName}}.crt
     with_items:
       - "{{ prod }}"
     when: sslcheck.results.stat.exists == False

However, my condition does not work… When I debug, I still see the result: false or true for sslcheck.results.stat.exists

So, why it doesn't work ?

RESULT:

fatal: [httpd1] => error while evaluating conditional: sslcheck.results.stat.exists
fatal: [httpd2] => error while evaluating conditional: sslcheck.results.stat.exists
fatal: [httpd3] => error while evaluating conditional: sslcheck.results.stat.exists

Best Answer

Where do the .results come from?`

If you read the stat module documentation, I think you should check with:

when: sslcheck.stat.exists == False