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

clickhosue jinja looping config.xml.j2

i have this list of ansible inventory [clickhouse] server01 ansible_host=10.1.1.1 name=server01 server02 ansible_host=10.1.1.2 name=server02 server03 ansible_host=10.1.1.3 name=server03 server04 ansible_host=10.1.1.4 name=server04 i have this…
ahmed
  • 39
  • 7
1
vote
1 answer

How to insert ansible dictionary variable as yaml in template output file

I have this dictionary env2: a: 20 b: 50 d: 90 Now i have this template file name: "test" env: "{{ env2 | to_nice_yaml(indent=8) }}" When i run the playbook i get output as env: "a: 20 b: 50 d: 90 " how can i get output as env: a: 20 …
rgd
  • 346
  • 1
  • 4
  • 15
1
vote
2 answers

Ansible: Add dictionary item into a YAML file

Can anyone help ? I am trying to add an additional item to a dictionary in yaml using Ansible. Here is the current file (site_vars.yaml) test: hello sites: - name: site 1 site: www.site1.com - name: site 2 site: www.site2.com And I am…
Ian Gregson
  • 199
  • 2
  • 8
1
vote
0 answers

Ansible install msi using windows_package module

I am trying to install Scale Out Software on my windows server. Instructions given by scale-out software for unattended installation are here According to the instructions, when I download the soss manually and run the below command in normal…
1
vote
2 answers

How to exclude an host in Ansible Jinja2 template for-loop?

I have a template named foo.yml.j2 used in an Ansible task to generate a foo.yml file: {% for host in ansible_play_hosts_all %} {{ host }}, {% endfor %} Everything works fine except I need something like the following statement:…
Sinux
  • 94
  • 7
1
vote
1 answer

How to convert dictionary to csv using jinja2 templates in ansible?

i need to convert the custom output variable to convert into dictionary then to generate csv file using jinja2 template below is the code - name: Executing the cmd (multipath -ll | grep dm- | awk -F' dm' '{print $1}') to get the device name …
Suganthan Raj
  • 2,330
  • 6
  • 31
  • 42
1
vote
0 answers

Unable to create 'Azure VM' with Custom Image Using 'Ansible'

I am trying to automate the process of updating an image in the scale set. So, I wrote an Ansible playbook to create a VM from a custom image and then, later, make some changes in that VM, capture an image of the said VM and change the image…
1
vote
3 answers

How to extract a specific value from input list as part of Ansible template file

I have the following input list (as part of inputfile) postgres_create_users: - {role: user1, password: password1} - {role: user2, password: password2} - {role: user3, password: password3} - {role: user4, password:…
dzbeda
  • 173
  • 2
  • 9
1
vote
1 answer

Ansible Playbook: Copy file with incrementing name

--- - hosts: webserver become: true tasks: - name: install web components apt: name={{item}} state=present update_cache=yes with_items: - apache2 - name: copy apache virtual hosts config copy: src=demo/demo.conf…
1
vote
1 answer

Jinja2 templating - Filter specific items - Ansible

I am wondering how it's possible to compare two lists in ansible with jinja2 templating and just get the difference between the lists. Let's say we have two lists: customers and exclude_customers customers: - name: A git: true version:…
Torben
  • 13
  • 3
1
vote
1 answer

Ansible incremental update for loop in set_fact not working

I have below registered variable output. And I am trying to get the unique tagIds from this output. Ansible Version: 2.9.6 "results": [ { "json": [ { "tags": [ { …
SNR
  • 460
  • 5
  • 20
1
vote
1 answer

How do I store 'ansible' hosts credentials in a different file using 'ansible-vault'?

Right now my inventory file looks like this: (using password-based authentication) [testvm] 104.231.213.32 ansible_user=worker ansible_password=Worker@12345 52.176.22.203 ansible_user=worker2 ansible_password=Worker2@12345 How do I store the…
1
vote
1 answer

Multiple choice variable to specify folder rights in Ansible Tower

I have a playbook that creates a directory in Ansible Tower. I have a survey with a multiple choice options to choose the permission for this folder. The playbook is: - name: Create a directory hosts: localhost become_user: root tasks: -…
raquel666
  • 15
  • 3
1
vote
1 answer

How to pass(use) google SA json in AWX to run anisble playbook which creates/updates/modify the VM in gcp?

I have an ansible-playbook, which will connect to GCP using SA and its JSON file. I have downloaded the JSONn file in my local and provided the path value to "credentials_file". this works if I run the playbook from my local machine. Now, I want to…
1
vote
1 answer

Ansible eht1 ipv4 address in j2 template

I'm currently working on a school assignment where i have to configure HAProxy to loadbalance between my two webservers. I'm deploying the machines via Vagrant in Virtualbox. After this, my Ansible playbook will run and starts off with configuring…