Home Unable to reference Jinja 2 variable inside a function
Reply: 0

Unable to reference Jinja 2 variable inside a function

user954
1#
user954 Published in April 25, 2018, 6:15 pm

So i have a slight bit of an issue with jinja variable reference within a function.

I've tried a handful of different methods to make this work, but none of them have yield any results. I hope some of you can help me out here!

{% set device_type = salt['grains.get']('device','') %}
{% set ip_addr = salt['network.ip_addrs'](' +device_type+ ')[0] %}

I'd like to have the variable device_type inside the salt function within ip_addr.

I have tried the following already and none of it gave any results:

{% set ip_addr = salt['network.ip_addrs'](\' +device_type+ \')[0] %}
{% set ip_addr = salt['network.ip_addrs'](' ~ device_type ~ ')[0] %}
{% set ip_addr = salt['network.ip_addrs']( {{ device_type }})[0] %}
{% set ip_addr = salt['network.ip_addrs'](' {{ device_type }} ')[0] %}

Does anyone know how I could replace the device_type within that function?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341492 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO