Questions tagged [ansible-template]

Use this tag for questions regarding writing and processing Ansible templates, Jinja2 syntax within Ansible, custom filters.

Ansible templates are processed by the Jinja2 templating language. Beside the default Jinja2 filters Ansible extends functionality with a lot of custom filters.

Templates are rendered from Ansible tasks through the template module or through the template lookup plugin.

638 questions
1
vote
1 answer

Registering service_facts variable in order to use it in a Jinja template

I'm trying to use service_facts to report if a service is in a running state, then email that out via a Jinja template. To grab the service info I'm using the following: - name: get service facts service_facts: - name: services check debug: …
d1530
  • 151
  • 8
1
vote
1 answer

How to use a variable defined in a previous task for use in a task where the conditional omits that host?

Effectively, I have two servers, and I am trying to get use output from the command of one of them, to configure the other, and vise versa. I spent a few hours reading on this, and found out that the hostvars process and dummy hosts is seemingly…
Viscosity
  • 311
  • 1
  • 2
  • 14
1
vote
1 answer

Combine dictionaries with condition and different structure

I'm looking to combine the two dictionaries by adding the ike_version to dic1 when the vpn_peer_ip match on both dic1 and dic2. Any help is very appreciated. dic1: 2aaac0695040: vpn_encryption: "ESP Tunnel PFS AES-256…
Michel
  • 13
  • 3
1
vote
1 answer

How to match/search a substring from a dict attribute that is a list

Here's the scenario: a playbook that calls a role to create users in multiple servers, including a VM Scale Set (where ansible_hostnames can't be predicted) - inventory is already being dynamically generated and works fine and not the issue a users…
1
vote
1 answer

Ansible set dictionary value based on another variable value

How can I implement below condition, to set value of dictionary config in Ansible ? Dictionary config and variable turn_on_encryption are both specified in same vars file. if turn_on_encryption == true, then: config: path: /var/www/html …
penguin
  • 133
  • 2
  • 15
1
vote
1 answer

Replace the key value in a list with the relevant matching values from another list in Ansible

I am trying to replace the key values in a dict inside a list(here only for the values inside Objectids) with the matching values from another list. Somehow i am only able to replace the 1st value but not iterating the whole list. Here the same key…
Vinny
  • 302
  • 2
  • 11
1
vote
1 answer

Ansible: Create Config based on File List

I'm a little confused on how to make this work and need a better understanding in terms of the ansible side of getting the following done: I have 500 images and I need to generate a default json config based on the image names. For…
mvelez83
  • 161
  • 1
  • 1
  • 9
1
vote
1 answer

Ansible - convert a comma delimited string into a space delimited string with double quotes

Following the great help I got for my last question I have another :). I have a requirement to convert the contents of the string variable: Targets debug: msg: - "Targets: {{ targets }}" Returns the following: ok: [host] => { "msg": [ …
user51760
  • 127
  • 8
1
vote
2 answers

Ansible: How to use split strings based on a delimiter(.) using maps for items present in list

In ansible if there is list of host names with fully qualified domain name: "groups[group_names[0]]": [ "node1.in.labs.corp.netin", "node2.in.labs.corp.netin" ] How to obtain only node names from these strings? Say , answer…
1
vote
1 answer

Jinja2 - create a dynamic variable using value of variable as part of the key of another variable

I am writing a jinja2 template for an Ansible role. I have this in my role/x/vars/main.yml switches: - hostname: foo customer: abc abc_secret_key: myP@$$word xyz_secret_key: myS3cr3t In my template, I want to reference the secret key…
pizzaguy39
  • 87
  • 5
1
vote
1 answer

How to remove the extra curly bracket while using jinja2 if condition in Ansible

I am creating a new JSON list using the jinja2 template and a json(base.json) file. The output is having extra curly brackets while iterating the json file which doesnot meet the condition to have a hubs array inside the json file. strong text [ …
Vinny
  • 302
  • 2
  • 11
1
vote
3 answers

How to save the return values of different hosts with separate variables

This is my playbook: --- - hosts: server gather_facts: false tasks: - name: shell: ping -c 1 -W 1 register: shell_result_var - name: set_fact: time_fact: "{{ ((shell_result_var['stdout_lines'][1] |…
1
vote
1 answer

How can I build a dict iterated with a lookup fileglob?

So far, I'm unable to figure out how to duplicate my current dict with k:v addition. Given this dict example: list0: ct0: entry: - dest: /tmp owner: u1 source: I'd like to get this result (source path being fetched with…
1
vote
1 answer

Conditional when win_service exists?

I'm creating playbook to install fluentbit on windows hosts. Everything is working properly but i'm getting error when creating service, it doesn’t fail the install as then everything is already in place but I would like to figure out how I could…
1
vote
1 answer

How to render/parse ansible output using json_query, getting null value

I have below output3.msg, how to get the desired output mentioned below? Please help in the syntax, check the one i have and suggest any modifications.I am in learning phase apologies for any mistakes Thank you. output3.msg { "msg": [ …
netv
  • 165
  • 2
  • 12