-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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