Skip to content

Instantly share code, notes, and snippets.

@jc1518
Created January 17, 2020 04:09
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 jc1518/b249a6930a1dc7bfcf85181df02844dd to your computer and use it in GitHub Desktop.
Save jc1518/b249a6930a1dc7bfcf85181df02844dd to your computer and use it in GitHub Desktop.
Ansbile playbook sample - get dictionary value
---
- hosts: localhost
vars:
accounts:
dev:
account: 123
contact: Jackie@123.com
uat:
account: 456
contact: Jackie@456.com
prd:
account: 789
contact: Jackie@789.com
gather_facts: no
tasks:
- name: Find account information method 1
debug:
msg: "{{ env }} account number is {{ item.value.account }}, contact email is {{ item.value.contact }}"
loop: "{{ lookup('dict', accounts) }}"
when: "env in item.key"
- name: Find account information method 2
debug:
msg: "{{ env }} account number is {{ accounts[env].account }}, contact email is {{ accounts[env].contact }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment