Questions tagged [jinja]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
72 views

SaltStack if condition failed mapping values while running command

I'm trying to echo a line into sudoers file like so but I can't figure out the correct syntax it's wanting for that specific command. gwconfig: cmd.run: {% if grains['ip4_gw'] == '192.168.1.1' %}...
rumplesmyboy's user avatar
0 votes
2 answers
686 views

Using variables within quoted strings in Ansible

Please take this working play example: - name: Display the URL hosts: all gather_facts: false vars: - host_domain: "testing.example.com" - default_url: "http://def....
Rino Bino's user avatar
  • 593
1 vote
1 answer
10k views

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 ...
Lasse Michael Mølgaard's user avatar
1 vote
1 answer
3k views

ansible/jinja extract multiple attributes from complex json return, rejecting specific matches

I'm trying to extract multiple attributes from a complex payload returned from an API call while rejecting members that have a certain value in the 'name' field. Consider the following payload: { &...
Apatt's user avatar
  • 21
0 votes
1 answer
430 views

Supplying hosts value to Ansible playbook via Jinja conditionals

I have an Ansible role that I want to execute on particular hosts based on a certain conditions. I want to populate the hosts from Ansible Tower survey. Here's my playbook: - name: HTTP Response ...
systrigger's user avatar
0 votes
1 answer
6k views

Ansible jinja2 template from JSON format provided as extra-vars

I have this jinja2 template: # {{ ansible_managed }} {% for vhost in nginx_vhosts %} {%- if vhost.name == item.name -%} # redirect www to non-www server { listen {{ nginx_port }}; listen [::]...
Bogdan Stoica's user avatar
1 vote
1 answer
898 views

Access dict value in variable from the same list item in Ansible

I'm using Ansible to deploy some virtual machines and I have a list variable defining the VMs. I'm wondering if I can have one of the dict items use another as a variable within the same list element. ...
Andrew Lamarra's user avatar
0 votes
1 answer
41 views

automated creation of a configuration file with ansible (or something else)

I have to create a pipeline in order to automate creation-deployment and update configuration file for network devices (switch-routers-firewall, mostly cisco). There's many ways i think to do the job ...
sam1975's user avatar
2 votes
2 answers
14k views

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-...
SergioLeone's user avatar
3 votes
2 answers
2k views

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/...
Casey's user avatar
  • 143
1 vote
1 answer
1k views

what does this jinja2 Filter do in Ansible? d({})

I try to understand what the following codeblock does inside an Ansible-Playbook environment: '{{ inventory__environment | d({}) | combine(inventory__group_environment | d({})) ...
geets's user avatar
  • 35
0 votes
1 answer
810 views

Ansible vmware_host_facts with a loop

I'm trying to get a list of all of the datastores across multiple ESXi hosts (they all sit in different vCenters so I'm having to use a loop with a dictionary to get the correct vCenter for the ESXi ...
jsjw's user avatar
  • 43
0 votes
1 answer
2k views

cloud-init script with jinja template is not being processed with iinja

I have a cloud-init script, that is using jinja templating. It looks like this: ## template: jinja #cloud-config merge_how: - name: list settings: [append] - name: dict settings: [no_replace,...
feroze's user avatar
  • 245
0 votes
2 answers
836 views

converting two lists into a specific dictionary so it can be sorted

I want to convert the following lists: rtt: [38,1,97] site: ["A","B","C"] into a dictionary like: dict: [ {'rtt':38, 'site':'A'},{'rtt':1, 'site':'B'},{'rtt':97,'site':'C'}] so i can sort it on ...
user2473664's user avatar
0 votes
1 answer
2k views

Loop through salt pillar to create file without knowing keys

Background: I need to make an XML file like this: <?xml version="1.0"?> <configuration> <appSettings> <add key="BaseOU" value="DC=myplace,DC=wan" /> <add key="...
static's user avatar
  • 141
5 votes
1 answer
9k views

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 ...
TheDESTROS's user avatar
3 votes
1 answer
12k views

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 ...
Gagandeep Singh Sekhon's user avatar
2 votes
1 answer
14k views

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 ...
Mario Nette's user avatar
0 votes
1 answer
1k views

Jinja "for loop" statement with multiple lines (saltstack)

When using salt for specifying user creation, it is unorganized to have the for statement in a single line. Example: {% for USR in 'hewey','dewey','loui' %} Is it possible to break this into ...
David's user avatar
  • 1
0 votes
1 answer
383 views

Haproxy healthcheck and backend section generation

I have a lot of sites and I want to do a http healthcheck for each one. Does it mean that I need to make a backend section for each site? If so, I need to generate it somehow. Can I achieve it with ...
warder's user avatar
  • 148
1 vote
1 answer
7k views

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 ...
Francis's user avatar
  • 481
1 vote
2 answers
1k views

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 '*...
M Haswell's user avatar
0 votes
1 answer
2k views

Ansible - manage installed apps and send output via email - variables are filling wrong

so i have this playbook, which checking, if there are installed selected packages. nothing special there. Then i would like to send an output to my email, if everything went right etc. --- - name: ...
helloweenx's user avatar
3 votes
1 answer
9k views

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 ...
peyoz's user avatar
  • 33
36 votes
9 answers
133k views

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 ...
pandoJohn's user avatar
  • 515
2 votes
1 answer
3k views

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 ...
pandoJohn's user avatar
  • 515
0 votes
1 answer
681 views

How to expand jinja inside imports for GCP Deployment Manager

I have a Deployment Manager template/schema and I want to dynamically include different startup-script options for cloud-init depending on the template.yaml I am calling. In my template.jinja I have: ...
xref's user avatar
  • 273
0 votes
1 answer
237 views

How do I use debconf in salt with pillars?

I have the following: newrelic-debconf: debconf.set: - name: newrelic-php5 - data: 'newrelic-php5/application-name': { 'type': 'string', 'value': '{{ salt['pillar.get']('newrelic:...
Andrei Dascalu's user avatar
0 votes
1 answer
3k views

How to pass urlencoded string to jenkins api using ansible?

I have to pass value to jenkins api. But jenkins api accept value in urlencode. I tried to use filter urlencode in ansible, but it gives error. - name: Add credential to add node uri: body: | ...
Nilesh's user avatar
  • 255
18 votes
1 answer
73k views

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": ...
ThatGuyOnTheNet's user avatar
8 votes
1 answer
23k views

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 ...
devxvda1's user avatar
  • 195
6 votes
4 answers
10k views

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] %} # {{ ...
Mikhail T.'s user avatar
  • 2,357
5 votes
1 answer
19k views

How to do multiline Jinja2 conditionals in single block? [closed]

The below code is rejected as syntactically incorrect: {% if inventory_hostname in groups.aptcache set cachehost = 'localhost' else set cachehost = groups['aptcache'] | first ...
Mikhail T.'s user avatar
  • 2,357