How can I use Ansible nested variable?

Per Ansible FAQ: Another rule is ‘moustaches don’t stack’. We often see this: {{ somevar_{{other_var}} }} The above DOES NOT WORK, if you need to use a dynamic variable use the hostvars or vars dictionary as appropriate: {{ hostvars[inventory_hostname][‘somevar_’ + other_var] }} So in your case: – debug: msg={{hostvars[inventory_hostname][Component].community_release_num}} Or: – debug: msg={{vars[Component].community_release_num}} Or (since … Read more

Ansible: filter a list by its attributes

To filter a list of dicts you can use the selectattr filter together with the equalto test: network.addresses.private_man | selectattr(“type”, “equalto”, “fixed”) The above requires Jinja2 v2.8 or later (regardless of Ansible version). Ansible also has the tests match and search, which take regular expressions: match will require a complete match in the string, while … Read more

Is it possible to use AngularJS with the Jinja2 template engine?

You have some options. 1) Change the delimiter notation for Angular: var app = angular.module(‘Application’, []); app.config([‘$interpolateProvider’, function($interpolateProvider) { $interpolateProvider.startSymbol(‘{a’); $interpolateProvider.endSymbol(‘a}’); }]); Whatever is chosen for the start and end symbols will act as the new delimiters. In this case, you would express a variable to Angular using {a some_variable a}. This approach has the … Read more

How can I pass data from Flask to JavaScript in a template?

You can use {{ variable }} anywhere in your template, not just in the HTML part. So this should work: <html> <head> <script> var someJavaScriptVar=”{{ geocode[1] }}”; </script> </head> <body> <p>Hello World</p> <button onclick=”alert(‘Geocode: {{ geocode[0] }} ‘ + someJavaScriptVar)” /> </body> </html> Think of it as a two-stage process: First, Jinja (the template engine … Read more

Reference template variable within Jinja expression

Everything inside the {{ … }} is a Python-like expression. You don’t need to use another {{ … }} inside that to reference variables. Drop the extra brackets: <h1>you uploaded {{ name }}<h1> <a href=”https://stackoverflow.com/questions/32024551/{{ url_for(“moremagic’, filename=name) }}”>Click to see magic happen</a> (Note that the url_for() function takes the endpoint name, not a URL path; … Read more