Getting started with 1Password for your growing team, or refining your setup? Our Secured Success quickstart guide is for you.
Forum Discussion
Former Member
4 years agoGet multiple items from the vault using Ansible loop
So, I am wondering if there is a way to get multiple items from the vault at once?
Here is the issue - I have a playbook with 20 or 30 secrets that are going to be stored inside 1Password. What I...
Former Member
4 years agoWell after some serious head banging I've actually managed to extract all information I needed.
Here is the result:
TASK [Are we there yet?] ***************************************************************************************************************************************************************************************************************************************************************************************************
ok: [snip] =>
password_secrets:
dashboard_password: DrtqaPW7jhUYCKXX
notesPlain: 'null'
some_label: the value
some_label3: the value3
some_label_2: the value2
And here is how:
```
- name: Get the item
item_info:
item: "{{ vault_title }}"
vault: Ansible
no_log: true
register: smtn
loop: "{{ secrets.fields }}"
- name: Set fields
set_fact:
fields: "{{ fields | default([]) + [item.op_item.fields] }}"
loop: '{{ smtn.results }}'
- name: Convert fields to an actual dictionary
set_fact:
field_dict: "{{ fields | first | dict2items }}"
- name: Set final items
set_fact:
final_items: "{{ final_items | default([]) + [item.value] }}"
loop: '{{ field_dict }}'
- name: Loop into dictionary
set_fact:
password_secrets: "{{ password_secrets | default({}) | combine ({ item.label : item.value | default('null') }) }}"
loop: '{{ final_items }}'
- name: Are we there yet?
ansible.builtin.debug:
var: password_secrets
```
Someone might find this useful. Anyhow, I think this should be much much much easier and something available right out of the box.