How to define hash (dict) in ansible inventory file? -


i able define hash(dict) below in group_vars/all:

region_subnet_matrix:   site1:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}a"   site2:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}b" 

but life of me, not figure out how define under hosts file

[all:vars] region_subnet_matrix="{   site1:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}a"   site2:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}b" }" 

i know incorrect, don't know right way. can enlighten me, please?

you can't use dict in inventory file because use ini format. preferred practice in ansible not store variables in main inventory file. host , group variables can stored in individual files relative inventory file.

assuming inventory file path is: /etc/ansible/hosts

if host named ‘testserver’ variables in yaml file @ following location made available host: /etc/ansible/host_vars/testserver.

the data in file might like:

region_subnet_matrix:   site1:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}a"   site2:     region: "{{ aws_region }}"     subnet: "subnet-xxxxxxx"     zone: "{{aws_region}}b" 

read more here.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -