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