Questions tagged [jinja]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
21 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-...
2
votes
2answers
93 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/...
0
votes
0answers
43 views

Saltstack - Jinja variable 'selinux_policy_dir' is undefined. New salt user

I'm a total n00b to writing salt states. The other day I created my first. It's just an automated deployment of a new auditing tool, along with a SELinux policy for it, etc. It seems to work fine. ...
1
vote
1answer
43 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({})) ...
0
votes
1answer
177 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 ...
0
votes
1answer
239 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,...
0
votes
2answers
31 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 ...
0
votes
1answer
213 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="...
3
votes
1answer
2k 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 ...
1
vote
1answer
2k 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 ...
1
vote
1answer
5k 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 ...
0
votes
1answer
305 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 ...
0
votes
1answer
149 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 ...
0
votes
0answers
4k 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 ...
1
vote
2answers
359 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 '*...
0
votes
1answer
922 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: ...
2
votes
1answer
6k 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 ...
26
votes
7answers
59k 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 ...
2
votes
1answer
2k 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 ...
0
votes
1answer
517 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: ...
0
votes
1answer
151 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:...
0
votes
1answer
2k 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: | ...
14
votes
1answer
46k 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": ...
4
votes
1answer
12k 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 ...
5
votes
3answers
4k 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] %} # {{ ...
3
votes
1answer
9k 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 ...