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

How to correctly define subelements in Ansible jinja2 template(with subelements)?

I'm writing ansible-playbook to divide nginx.conf with includes. In my opinion it would be more comfortable to use nginx.conf with such option cause I can include or exclude some config block at playbook vars. At current time I have trouble with…
Kein
  • 165
  • 2
  • 15
0
votes
1 answer

How to specify multiple values to ansible_host magic variable

I have a question on how do we give multiple values to "ansible_host" magic variable. I have my hosts.yml like below: all: hosts: ansible: host: children: applications: children: java_applications: …
0
votes
0 answers

Unable to run command using Sudo in Ansible

I’m running an Ansible job wherein I’m switching the user to a Service Account to run a certain command. I am able to switch the user and confirm the same using the become method and then a raw: whoami. When in the same scenario post the become…
0
votes
1 answer

Use jinja template in a json property name with Ansible

I don't find a way to do the following template: - debug: msg: {"registries":{"{{docker_registry.url}}":{"username":"{{docker_registry.user}}","password":"{{docker_registry.password}}"}}} Ansible detects automatically a json and does not inject…
Arzhr
  • 435
  • 8
  • 22
0
votes
1 answer

Jinja template in Ansible treats "dest" as a directory instead of as a file

tl;dr Ansible's template module treats a template destination as a directory instead of as a file. What am I missing? Situation: I am using paulfantom's ansible-restic role in another role, named backups-role. I am testing my role with a dummy…
raneq
  • 117
  • 7
0
votes
1 answer

How can I provide multiple value in a variable using, separator - Ansible playbook

- name: Application deployment hosts: "{{ target_hosts }}" gather_facts: no become: yes become_method: su become_user: 'root' roles: - APP_deployment vars: - password_supersu: 'Abcdefg@Linux' -…
0
votes
1 answer

How to extend ansible playbooks to achieve complex conditions?

I understand that ansible is limited to being a configuration tool i.e., we create configurations in yaml files and python scripts does execution by looking at the configuration. There are howevever a useful attribute when that will help in deciding…
GP92
  • 433
  • 1
  • 12
  • 30
0
votes
1 answer

Create Azure Keyvault secrets via Ansible

Ansible version 2.7.6 Ansible playbook looks like this: - hosts: localhost name: Create instance of Key Vault tasks: - name: Create a secret azure_rm_keyvaultsecret: secret_name: test25 secret_value:…
0
votes
1 answer

Ansible didnt pass down variables between files

I was trying to use Ansible to put some jinja2 templates to a directory, e.g. path/from/*.j2 to path/to/*.txt. In my ./defaults/main.yml: --- test_var: - a: 1 b: 2 - a: 10 b: 20 In my ./tasks/main.yml: --- - name: "Copy file" …
Peter
  • 25
  • 4
0
votes
0 answers

How do I manage configuration of INI file with of many servers, with the help of ansible, whose values are dynamic on basis of server?

I am having some problem while doing changes in INI files on many servers, with help of ansible. I have multiple INI files on different servers, and the values will be different for same option on that INI file. For Eg. a configuration for a server…
khush
  • 1
  • 2
0
votes
2 answers

how to run a task if only a variable is defined

I have the following task : -name : task name cron: ... ... ... when: "{{ vars[cname].cron }}" is defined i want to run a task only if the variable server1.cron for the the host server1 and server2.cron for the host server2…
Midokate
  • 95
  • 3
  • 11
0
votes
1 answer

how to get ansible inventory file name as a variable

I have a situation where three Jenkins jobs running which uses ansible for the deployment. This jobs uses there own inventory files like /opt/abc/ci1.inventory, /opt/abc/ci2.inventory, /opt/abc/ci3.inventory etc. For example if first jenkins job is…
0
votes
1 answer

Ansible render variable from set variable

I want to use jinja2's template for generate configuration. But I'm stuck with this. I use set for create new variable, after that I need to use fallowing string as new variable for rendering. My sample code which show what I want to achieve:…
3sky
  • 830
  • 1
  • 7
  • 16
0
votes
1 answer

Ansible: customizable template filenames

I'm writing an Ansible role where I have some templates that must be present multiple times with different names in a single destination directory. In order not to have to handle each of these files separately I would need to be able to apply…
Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
0
votes
1 answer

Dynamically generating complex data structures in Ansible

The way I came up with is: - name: ... set_fact: _forwards: '{% set _r = [] %}{% for _g in _guests %}{{ _r.append({ "p_from_interface": "!lxcbr0", "p_from_port": hostvars[_g].ansible_port, …
x-yuri
  • 16,722
  • 15
  • 114
  • 161