On Fri, 7 May 2021 01:53:22 -0700 (PDT)
Pabolito Garci <paboli...@gmail.com> wrote:

>     - name: read credentials from csv file
>       set_fact:
>         hpe_sut_cred_user: "{{ lookup('csvfile', inventory_hostname +' 
> file=hpe_sut_security_store.csv delimiter=; col=1') }}"
>         hpe_sut_cred_pwd: "{{ lookup('csvfile', inventory_hostname +' 
> file=hpe_sut_security_store.csv delimiter=; col=2') }}"

Lookup *file* will decrypt it. Parse the file on your own and create
a dictionary, e.g.

    - set_fact:
        hpe_sut_cred: "{{ hpe_sut_cred|default({})|
                          combine({_arr.0: {'user': _arr.1,
                                            'pwd': _arr.2}}) }}"
      loop: "{{ lookup('file', 'store.csv').splitlines() }}"
      vars:
        _arr: "{{ item.split(';') }}"
      run_once: true

Then, use it to set the variables

    - set_fact:
        user: "{{ hpe_sut_cred[inventory_hostname]['user'] }}"
        pwd: "{{ hpe_sut_cred[inventory_hostname]['pwd'] }}"

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20210507131633.2b82714b%40gmail.com.

Attachment: pgpvAQo8wxx3K.pgp
Description: OpenPGP digital signature

Reply via email to