Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnoldyahad/971e96005dc6223e66a21d5e9b845725 to your computer and use it in GitHub Desktop.
Save arnoldyahad/971e96005dc6223e66a21d5e9b845725 to your computer and use it in GitHub Desktop.
ansible concatenate item / element of list of dictionaries / dict
---
- name: concatenate list elements of dictionary
hosts: all
gather_facts: no
vars:
users:
- username: alice
email: alice@example.com
- username: bob
email: bob@example.com
tasks:
- debug:
msg: "{{ users | map('json_query','email') | list | join('; ') }}"
delegate_to: localhost
$ ansible-playbook playbooks/ansible_concatenate-list-of-dict.yml
PLAY [concatenate list elements of dictionary] *****************************************************************************************************************************************
TASK [debug] ***************************************************************************************************************************************************************************
ok: [your_host -> localhost] => {
"msg": "alice@example.com; bob@example.com"
}
PLAY RECAP *****************************************************************************************************************************************************************************
your_host : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment