I assume what you want is `with_together` for your last task:

- name: Generate RSA-Key
  community.crypto.openssl_privatekey:
    path: /opt/cert/{{item.0.username}}.key
    size: 2048
  when: item.1.stat.exists == False
  with_together:
    - "{{roles}}"
    - "{{rsa.results}}"

Notice the use of `item.1.stat.exists` and `item.0.username`

On Fri, Aug 20, 2021 at 8:09 AM Иван Копылов <[email protected]> wrote:

> Hello!
>
> Here is the problem:
>
> - name: Check for RSA-Key existence
>   stat:
>     path: /opt/cert/{{item.username}}.key
>   with_items: "{{roles}}"
>   register: rsa
>
> - name: debug
>   debug:
>     var: item.stat.exists
>   loop: "{{rsa.results}}"
>
> - name: Generate RSA-Key
>   community.crypto.openssl_privatekey:
>     path: /opt/cert/{{item.username}}.key
>     size: 2048
>   when: item.stat.exists == False
>   with_items:
>     - "{{roles}}"
>     - "{{rsa.results}}"
>
> The error that i received - The error was: error while evaluating
> conditional (item.stat.exists == False): 'dict object' has no attribute
> 'stat'
>
> Debug task goes just well - "item.stat.exists": true
>
> I am beating around this about 2 days already... What am i dooing wrong
> and how to make this work?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f103126d-ed49-4f33-a25f-c4d18ebf0a5dn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f103126d-ed49-4f33-a25f-c4d18ebf0a5dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v80iVwbO_ZqG_VxwXJjEgkqpaXZc4biyvAg7L%2Bk4fqK4A%40mail.gmail.com.

Reply via email to