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 rulai-jianfang/96834dd345f649c6c9aed1eda391439c to your computer and use it in GitHub Desktop.
Save rulai-jianfang/96834dd345f649c6c9aed1eda391439c to your computer and use it in GitHub Desktop.
Ansible example which shows how to reach nested variable with dynamic elements
# Example which shows how to reach nested ansible variable which is partially different.
# Run that plabook with ansible-playbook -e "env=test" ansible-nested-variable.yml
---
#
- hosts: localhost
connection : ssh
gather_facts: no
vars:
cidr_blocks:
vpc_production_cidr_block: "10.10.0.0/28"
vpc_infra_cidr_block: "10.20.0.0/28"
vpc_test_cidr_block: "10.30.0.0/28"
tasks:
- name: Show all CIDRs
debug:
msg: "{{ cidr_blocks}}"
- name: Show spesific CIDRs
debug:
msg: "{{ cidr_blocks['vpc_%s_cidr_block' | format(env)] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment