On Mon, 8 Aug 2022 23:07:32 -0700 (PDT)
"[email protected]" <[email protected]> wrote:

> insights.jdbc.password={{ postgres_create_users ??? }}

Create a dictionary. The best choice might be the same place the list
*postgres_create_users* comes from. For example,

shell> cat group_vars/all/postgres_create_users.yml 
postgres_create_users:
  - {role: user1, password: password1}
  - {role: user2, password: password2}
  - {role: user3, password: password3}
  - {role: user4, password: password4}
pcu_dict: "{{ postgres_create_users|
              items2dict(key_name='role',
                         value_name='password') }}"

gives

  pcu_dict:
    user1: password1
    user2: password2
    user3: password3
    user4: password4

The usage is trivial. For example, the template

shell> cat templates/server.xml.j2
insights.jdbc.password="{{ pcu_dict.user4 }}"

and the playbook

shell> cat pb.yml
- hosts: localhost
  tasks:
    - debug:
        msg: "{{ lookup('template', 'server.xml.j2') }}"

gives (abridged)

shell> ansible-playbook pb.yml

TASK [debug]
**************************************
ok: [localhost] => msg: |-
    insights.jdbc.password="password4"

-- 
Vladimir Botka

-- 
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/20220809124859.314feda9%40gmail.com.

Attachment: pgpBBJGey_g2J.pgp
Description: OpenPGP digital signature

Reply via email to