Can't proceed with_items and register

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?

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

Thank you, Matt! Now it works as it should be, thanks again)

пятница, 20 августа 2021 г. в 16:36:08 UTC+3, Matt Martz: