Hi, I like to know if possible made reference of a variable inside other variable.
Example:
{{ansible_local.oracle.credentials.“{{websphere_mb.odbc.schema_name}}”}}
with this I try to build the final variable name that if I put manually works, but like to don’t hardcode Schame_name and read from vars file.
this can be possible?
Thanks
Ale
no moustache stacking
{{ansible_local.oracle.credentials[{{websphere_mb.odbc.schema_name]}}
Thanks Brian,
THis is how work for me.
{{ansible_local.oracle.credentials[websphere_mb.odbc.schema_name]}}
And ansible_local really come from other node that I ask using
- name: Get sql master facts
setup:
delegate_to: “{{websphere_mb.odbc.host}}”
register: db_facts
tags: mbconfig
Some better way to do this?
THanks
Ale
Ale/Brian
I’m trying to use variables in variables as well…not sure how to do it. I’m using set facts
Below is the when condition:
hardcoded:
when: “‘{{ hostvars[groups[‘app-a1’][0]][‘target_app_build’] }}’ != ‘{{ hostvars[groups[‘app-a1’][0]][‘actual_app_build’] }}’”
what I need:
when: “‘{{ hostvars[groups[‘app-a1’][{{ partition }}]][‘target_app_build’] }}’ != ‘{{ hostvars[groups[‘app-’][{{ partition }}]][‘actual_app_build’] }}’”
Here {{ partition }} - is an extra variable
It doesn’t seem to be working for me.
Thanks,
Virendra
same rule no nesting of moustaches:
when: "{{ hostvars[groups['app-a1'][partition]]['target_app_build']
!= hostvars[groups['app-'][partition]]['actual_app_build']}}"
Rob_White
(Rob White)
6
If there is no moustache stacking does that mean variables inside variables is impossible?
I.e.
environments:
prod:
vpc_id: 12345
stg:
vpc_id: 67890
env: prod
debug: msg={{ ‘environments.’ + env + ‘.vpc_id’ }}
This just gives me a string of ‘environments.prod.vpc_id’ but what I want is ‘12345’
I’m completely new to all this, but looking at http://jinja.pocoo.org/docs/dev/templates/#variables
I’d try to do it like this:
`
environments:
prod:
vpc_id: 12345
stg:
vpc_id: 67890
env: prod
debug: msg={{ environments[env].vpc_id }}
`