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 include a variable file in Ansible?

I have the following playbook: - hosts: localhost tasks: - set_fact: main_body="test_main" - template: src: test_src.j2 dest: /tmp/test_dest.j2 And the following Jinja template: main () { {{ include main_body }} } When…
ceving
  • 21,900
  • 13
  • 104
  • 178
0
votes
2 answers

Comparing variables in template to build JSON - Ansible

Starting off with Ansible and I am trying to use ReST API to interact with an external application.Maybe I am missing something simple here. I am trying to compare every host in my inventory file with the POD name specified in the variable file…
Dee
  • 1
  • 1
-1
votes
1 answer

How to output loop.index in jinja

I want to be able to output the loop.index iteration to my template , i am using ansible and i have template file.j2 and inventory file have the below group [all_servers] app01 ansible_host=10.10.1.100 app02 ansible_host=10.10.1.102 app03…
-1
votes
1 answer

How can I rewrite my ansible playbook so I can pass multiple values to a variable instead of duplicating the code each time?

How do I supply multiple values to the variable delete_signer_cert_cert_id in the following playbook and instead of duplicating the code multiple times? - name: Delete expired signer certs hosts: all ignore_errors: true connection: local …
-1
votes
1 answer

How to avoid replacement of new lines with \n in Ansible file lookup?

I am trying to fetch the content of foo.txt as it is however when I am doing a lookup the new lines are getting replaced with \n. How to avoid this and get the content of file as it is? foo.txt: This is dummy1 This is dummy2 This is dummy3 This is…
-1
votes
1 answer

Need help on Ansible issue

I have a requirement to create the property file like below from Ansible. "demo_cluster","demo_cluster_1",64,256 "demo_cluster1","demo_cluster_2",64,256 "demo_cluster2","demo_cluster_3",64,256 So for I have a created template file where I have…
-1
votes
1 answer

How to create a Jenkins Job with parameters using ansible?

I need a help in Jenkins Job Creation with parameters using Ansible. I have checked many documents but not helping much. I have checked https://docs.ansible.com/ansible/latest/collections/community/general/jenkins_job_module.html but not getting…
-1
votes
1 answer

Using inventory_hostname to Reference Dictionary Key Value in Ansible

I want to put a list of names and descriptions into a CSV, and then for each host in hostvars, pull out the corresponding descriptions in the CSV. Below is my code --- # Goals # 1. Read CSV into dictionary # 2. For each host in the playbook, print…
-1
votes
1 answer

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not find or access /home/jenkins/workspace/NonProd.json on the Ansible Controller

I am trying to copy a JSON file using Ansible template to localhost and run a cURL command to import Datadog dasboard. Jenkins error: TASK [datadog-dashboard : Import Datadog Dashboard in main] ******************** 16:54:24 included:…
Ashish Karpe
  • 5,087
  • 7
  • 41
  • 66
-1
votes
1 answer

create ansible dict from two list with a condition

I have many strings like this stored in list one set bgp x vlan y tags-vlan bgp z, set bgp x1 vlan y1 tags-vlan bgp z1, . . . . and a second list contain values like this: f, j, h, m from the first list of strings, i want to trim it and create…
GenZ
  • 49
  • 4
-1
votes
1 answer

How to copy mutiple ansible template files to destination using group_var dictionary?

I am attempting to copy multiple template files to my unix machine. Issue is, I have multiple systems, so the templates are variablized based off the group_var file, app.yml. User parses the system_name to the ansible playbook which then gathers the…
test1 1
  • 47
  • 7
-1
votes
1 answer

ansible jinja template pass variable

I want to pass multiple ip list and same port in single variable using ansible jinja. I want output in configuration file like this. value=["10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200", "10.0.0.1:8200"] or if I can pass ["10.0.0.1:8200",…
-1
votes
1 answer

Ansible Java 17 priority task has no permission

I am trying to create a task in Ansible which makes my GraalVM Java JDK as the default installation. I do the following: - name: Make GraalVM Java as the selected version community.general.alternatives: name: java path:…
-1
votes
1 answer

Ansible use inventory host inside template

I'm trying to get the IP of my server in a template, to set up a monitoring process with a single defined IP. Configuration example The inventory file prod_srv_mqtt: hosts: mqtt-broker-01: ansible_host: 10.10.10.10 mqtt-broker-02: …
Manticore
  • 441
  • 5
  • 24
-1
votes
1 answer

Need to get miniconda basebath from mac using ansible

Hi I am trying to get miniconda base path, to set the PATH but fail to get it, tried with shell and command , output getting as same input : "conda info | grep -i 'conda av data dir'|awk '{print $6}'" -name: get_conda_path shell: echo $(conda info…