Can't proceed with_items and register

29 views
Skip to first unread message

Иван Копылов

unread,
Aug 20, 2021, 9:09:44 AM8/20/21
to Ansible Project
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?

Matt Martz

unread,
Aug 20, 2021, 9:36:08 AM8/20/21
to ansible...@googlegroups.com

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`

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f103126d-ed49-4f33-a25f-c4d18ebf0a5dn%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

Иван Копылов

unread,
Aug 20, 2021, 12:07:53 PM8/20/21
to Ansible Project
Thank you,  Matt! Now it works as it should be, thanks again)

пятница, 20 августа 2021 г. в 16:36:08 UTC+3, Matt Martz:
Reply all
Reply to author
Forward
0 new messages