help on dynamic with_dict xxxx.results[0].stat.exists == false

Hi Group,

I am trying to establish a logic on a creating web server self signed certificates.
(please note that this issue could be related any other task like depending on files
in directories, etc.)

Logic is that I would like to create subsequent files (as cert request and the newly signed key
this instance).

I am doing stat on the private key earlier in the role. If the private key does NOT
exists, I am going to create csr and eventually signed pem file.

Please note that my entire logic worked when I did one vhost in a time, perfect.
However, when I wanted to do them in a “loop” which more professional and tidy, it hit
brick wall since with_dict alters to stat results explained in documentation (hint, hint)
After a bit of debugging I have managed to locate location of stat values, but now
I am stuck on
when: server_private_key.results[0].stat.exists == false
issue. How can I match the item number dynamically on results[0] rather than hard coding it to zero?
(as can easily be done on any primitive programming language)

Best Regards: JP

- stat: path={{item.value.ssl_dir}}/{{item.value.ssl_name}}.key
register: “server_private_key”
with_dict: “{{ssl_certs}}”

—snip—

- name: SSL ‘generate-cert-request’
shell: “/usr/bin/openssl req -new -subj "{{item.value.subject}}" -key {{item.value.ssl_dir}}/{{item.value.ssl_name}}.key -out {{item.value.ssl_dir}}/{{item.value.ssl_name}}.csr”
when: server_private_key.results[0].stat.exists == false
with_dict: “{{ssl_certs}}”
tags: [‘generate-server-key-Step-2’]

Hi,

i think this can be solved if you can make you ssl_certs a list of dicts and use with_indexed_list
http://docs.ansible.com/playbooks_loops.html#id22

I think my question is more “fundamental” as

How can I capture and use the array member number of with_dict in results[0].stat.exists like on any primitive language as an example below.

#!/bin/bash
for i in 1 2 3 4 5
do
   echo "Welcome $i times"
done

Sample outputs:

Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times

Best Regards: JP

you can use sequence, start at 0 and end at list length