Skip to content

Instantly share code, notes, and snippets.

@fty4
Last active March 6, 2022 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fty4/7f73242a5170192a947dabbf9dd46b4c to your computer and use it in GitHub Desktop.
Save fty4/7f73242a5170192a947dabbf9dd46b4c 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