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
2
votes
1 answer

Ansible parse for a specific line in resulted registered var

Under my ansible playbook , i ve a task which execute a script: - name: Execute Update on selected databases shell: "./script_update.sh server007 {{item}} {{bdd_config[item].updateFile }}" with_items: "{{selected_DBS}}" register:…
firasKoubaa
  • 6,439
  • 25
  • 79
  • 148
2
votes
1 answer

Ansible Nested Variable Regex search

How do we do a wildcard search with Ansible nested variable? YAML test: name: address: zipcode: 12345 Ansible Template Variable {{ test[name][addre*].zipcode }}
Amala
  • 161
  • 1
  • 3
  • 13
2
votes
2 answers

Ansible jinjia2 template whitespaces control

Question How do I get the desired output? Code yaml nodeStatusUpdateFrequency: {% if nodeStatusUpdateFrequency is defined -%} {{ nodeStatusUpdateFrequency }} {% else -%} {%- if nodeStatusUpdate == 'Fast' -%} 4s {%- elif…
张馆长
  • 1,321
  • 10
  • 11
2
votes
1 answer

Trying to create a .csv file with Ansbile Copy module, content option, but it only writes last iteration of loop

I am trying to create a csv file with the following Ansible playbook: - name: Find Fex Enclosure hosts: MAQ gather_facts: no connection: local tasks: - name: GET VENDOR & OS OF THE EQUIPEMENT …
Jose Garcia
  • 21
  • 1
  • 4
2
votes
1 answer

Ansible how to store output of register in list when iterated over inventory

I am running a shell command, this command runs for all hosts listed in my inventory file. I am then using register to define the variable, when i retrieve these values for debug messages i see register variable for all hosts printed for all IP in…
2
votes
1 answer

How to run validation on Ansible template task when using check mode?

When running Ansible in check mode (--check), it seems the validate command is not run for template tasks: - name: Nginx is configured template: src: nginx.conf.j2 dest: /usr/local/etc/nginx/nginx.conf validate: /usr/local/sbin/nginx…
Adam Lindberg
  • 16,447
  • 6
  • 65
  • 85
2
votes
1 answer

Ansible group_vars in template module

I want to copy file using jinja2 templating in ansible. I have one file inside templates/file.j2 and inside that file I have one variable defined fos.broker.host={{ fos.broker.host }} Inside group_vars/stage I have the value of this variable…
Aziz Zoaib
  • 661
  • 8
  • 21
2
votes
0 answers

Ansible: set_fact variables across hosts blocks

Not Duplicate: This is not like accessing other hosts' yaml data like described here. This is setting my own variable during execution and want to access it later I am using ansible-playbook to perform some task on 2 vm pools. Assume that I have…
Ashwin
  • 993
  • 1
  • 16
  • 41
2
votes
2 answers

Ansible loop : How can I loop through the array using with_sequence for index

I have multiple arrays with same length. I need to loop through the length and call the elements. I tried the below one and failed. Can you please let me know where I did wrong in this. Or is there any better approach to loop through array…
2
votes
3 answers

Ansible loop error

I recently started writing playbooks. Below is my task: - name: apache templates template: src: "{{ item.templatename }}" dest: /opt/apache/default/"{{ item.config }}" loop: - { templatename: 'apache_webconf.j2', config:…
2
votes
1 answer

Ansible variable from output

I would like to extract some words from an Ansible output. For example, I would like to extract from sudo monit status command the bolded words(** **) and store them in 2 variables(let's say variable 'A' for OK and variable 'B' for the uptime…
Romain
  • 171
  • 1
  • 3
  • 15
2
votes
2 answers

Extend ansible role?

I am writing my first ansible playbook and try to configure php 7 by using already existing roles. I found 2 roles that nearly suit my needs but both of them do not offer the flexibility I want for creating php.ini…
maxhb
  • 8,554
  • 9
  • 29
  • 53
2
votes
1 answer

How to read an Ansible variable from a string containing YAML?

I have a task which runs an uri call to get a JSON file containing a YAML fragment (it is obtained from Rancher API). I'm able to extract the YAML fragment using the following task - name: generate_stack_call_body.yml read docker compose from…
Riduidel
  • 22,052
  • 14
  • 85
  • 185
2
votes
0 answers

ansible template using with_items and with_dict in same task

ansible 2.3.0.0 with python version 2.7.5 host_vars: manager: Tom asst_managers: - Gail - Susan - Larry hotels: hotel1: address: 1113 Mockingbird ln rooms: 40 hotel2: address: 2222 BlueJay Ln rooms:…
Bill Nolf
  • 21
  • 3
2
votes
2 answers

Ansible concat vars to string

I've spent most of the day trying to solve this problem and have thus far failed. I am building some playbooks to automate functions in Splunk, and am attempting to convert a list of hosts from an inventory group E.G.…
AlmostGosu
  • 65
  • 6