# help on dynamic  with\_dict    xxxx.results\[0\].stat.exists == false

**URL:** <https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467>\
**Category:** Ansible Project\
**Created:** [June 11, 2015, 10:09am UTC](https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467 "2015-06-11T10:09:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnP](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@JohnP](https://forum.ansible.com/u/JohnP)\
**Post date:** [June 11, 2015, 10:09am UTC](https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467/1 "2015-06-11T10:09:33Z")

</div>

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’]**

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [June 11, 2015, 10:26am UTC](https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467/2 "2015-06-11T10:26:35Z")

</div>

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](http://docs.ansible.com/playbooks_loops.html#id22)

---

<div class="post-metadata">

**Author:** ![JohnP](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@JohnP](https://forum.ansible.com/u/JohnP)\
**Post date:** [June 11, 2015, 10:36am UTC](https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467/3 "2015-06-11T10:36:58Z")

</div>

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.

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

```

Sample outputs:

```auto
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times

```

Best Regards: JP

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 11, 2015, 1:34pm UTC](https://forum.ansible.com/t/help-on-dynamic-with-dict-xxxx-results-0-stat-exists-false/18467/4 "2015-06-11T13:34:27Z")

</div>

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