Questions tagged [jinja]

32 questions
32
votes
8 answers

Ansible: Conditionally define variables in vars file if a certain condition is met

Depending on the value(True/False) of a variable defined into the group_vars I am trying to define some variables in a vars file. Their value depends on the group var's value. My current var file looks like this: {% if my_group_var %} test: var1:…
pandoJohn
  • 375
  • 1
  • 4
  • 8
16
votes
1 answer

Loop over Ansible variable array in Jinja2 template

when Ansible gathers facts about hosts, it for example gets all the mounts of the host: "ansible_mounts": [ { "block_available": 7800291, "block_size": 4096, "block_total": 8225358, …
ThatGuyOnTheNet
  • 173
  • 1
  • 1
  • 6
7
votes
1 answer

SaltStack | How to assign the shell output from cmd.run to Jinja variable?

Problem Unable to assign the output from cmd.run in my Salt State. The condition always return true even if the load_avg in the minion is not really equal or beyond the threshold. I also included in the configuration the things I have…
devxvda1
  • 185
  • 1
  • 1
  • 7
5
votes
1 answer

Reject in ansible list variable

I have such a variable: apps: - {name: kapitalism, extension: .war} - {name: socialism, extension: .war} - {name: somethingelse, extension: .ear} And I need to make another one based on it, which will not include some of the list. I'm trying…
TheDESTROS
  • 375
  • 3
  • 9
5
votes
4 answers

How to trigger a custom error from inside a Jinja template?

Though Ansible itself has a way for triggering a custom error, I can not find anything similar for Jinja. My current method uses a syntax error: {% if 'ansible_mounts' in hostvars[host] %} # {{ host }} knows its mount-points {% else %} # {% error!!…
Mikhail T.
  • 2,272
  • 1
  • 22
  • 49
4
votes
1 answer

How to do multiline Jinja2 conditionals in single block?

The below code is rejected as syntactically incorrect: {% if inventory_hostname in groups.aptcache set cachehost = 'localhost' else set cachehost = groups['aptcache'] | first endif %} cache={{ cachehost }} I hope, my…
Mikhail T.
  • 2,272
  • 1
  • 22
  • 49
3
votes
1 answer

use a variable inside json_query in ansible/jinja

I'm trying to loop on a custom dictionary in ansible in order to check some mount points on a linux server, and I'm a little bit in trouble finding the correct solution, find below my playbook right now: - name: Check lvm devs hosts: localhost …
peyoz
  • 33
  • 1
  • 3
3
votes
2 answers

How to select network interface given ip address in ansible across Debian and FreeBSD?

I'm looking for an expression to fetch the interface name given an ip address assigned to that iface, across Linux and FreeBSD. This question is based on this answer: https://serverfault.com/a/948288/416946 This jinja2 expression will, on Debian,…
Casey
  • 143
  • 8
2
votes
1 answer

Ansible: Loop over registered output in the next task

Ansible version: ansible 2.6.2 python version 2.7.5 I am struggling to loop over registered IP addresses from one task in other using with_items and have a debug output from an ansible playbook which gives this: The playbook: - name: Check DVS…
2
votes
1 answer

Ansible: How to get a subelement of a nested list of dictionaries

I'd like to build our DNS zones via Ansible. The user should just maintain one variable for the forward-lookup zones (e.g. foo.bar). Reverse-lookup zones (0.0.10.in-appr.arpa) should be auto-generated with Ansible. The forward-lookup zone variable…
Mario Nette
  • 51
  • 1
  • 1
  • 6
2
votes
1 answer

Ansible:how to adapt the output format of map (with extract) filters

I am trying to extract the IP addresses of the hosts that are part of two groups and use them in a .xml config file. The problem I'm facing here is the output generated by the expression used into the jinja template. What I want to achieve is an…
pandoJohn
  • 375
  • 1
  • 4
  • 8
2
votes
2 answers

Dynamically creating a list in Ansible with jinja

I need to dynamically set a new list type variable list var. Here's a basic playbook example: vars: app_instances: - host_name: host1-domain inst_count: 3 - host_name: host2-domain inst_count: 1 - host_name:…
SergioLeone
  • 141
  • 1
  • 4
1
vote
1 answer

Avoiding jinja templating delimiter in when statements

I'm currently porting my Ansible playbooks from version 2.1 to 2.7. Ansible now prints a warning if I use jinja templating delmiters such as {{ .. }} in a when clause. [WARNING]: when statements should not include jinja2 templating delimiters such…
Francis
  • 381
  • 2
  • 6
  • 17
1
vote
2 answers

Saltstack state.apply determine whether it is being run in test=True mode ?

We are using serverdensity (BETA MODULE - https://docs.saltstack.com/en/latest/ref/states/all/salt.states.serverdensity_device.html) with salt and have hit the (bug?) where if you try a : salt '*SERVER-01*' --state-output=mixed state.apply…
M Haswell
  • 31
  • 5
1
vote
1 answer

Inserting Jinja variable into a quoted string

I am building a Podman container that runs Samba Active Directory with Bind9 and Freeradius support using Ansible and have runned into a bit of a snag. Samba runs fine with DLZ_BIND as backend in my container, but I need to integrate Freeradius into…
1
2 3