How to use another variable in Ansible variable? -


how make echo statement here correct?when use ansible debug module able correctly value, not in shell module.

cat /data/info.txt a:8080,b:8081,c:8082 
cat /data/num 0 
 - hosts: dev    remote_user: root    gather_facts: false    tasks:      - name: dir path , port info        shell: cat /data/info.txt        register: info       - name: last num        shell: cat /data/num        register: num       - name: test        shell: echo {{ info.stdout.split(',')[{{ num.stdout }}].split(':')[0] }} >>/tmp/test.txt 

once open jinja2 expression {{, should use bare variables until terminated }}. quoting faq:

another rule ‘moustaches don’t stack’. see this:

{{ somevar_{{other_var}} }}  

the above not work


what might looking (because still didn't include expected result) is:

shell: echo {{ info.stdout.split(',')[ num.stdout|int ].split(':')[0] }} >>/tmp/test.txt 

on top of not stacking moustaches, need pay attention types , cast second value (retrieved /data/num) integer.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -