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

Problem : accessing a variable with name that changes in a loop

this is the content of my playbook: - name: Download checksum get_url: url: "{{ item.value.url }}.sha1" dest: "/VAR/{{ ansible_user }}/tmp/{{ item.value.dest }}.sha1" mode: 0640 timeout: 300 force: yes with_dict: "{{…
Midokate
  • 95
  • 3
  • 11
-1
votes
1 answer

need to send mail using attachment and password encryption in ansible

I am facing issue with by below playbook on 2 scenarios 1) How to send mails using ansible without defining the password of the account. using SMTP username and password now in the play to send mail. but is there any alternate way to avoid…
-1
votes
1 answer

Ansible task to to get the localhost ip address and replace in the destination file with value

i am running below task and replacing whole content in the destination file with ip address --- - hosts: localhost connection: local tasks: - debug: var=ansible_all_ipv4_addresses - debug: var=ansible_default_ipv4.address - copy:…
Vijaya Krishna
  • 35
  • 1
  • 12
-1
votes
1 answer

Ansible Jinja Template config and stdout comparison

My pseudocode: 1. Get the ntp server config from "sh run" 2. Store that to a list 3. Jinja template generates the required config. I am passing the ntp_server IPs via -e (extra variables). 4. Add the config from 3, compare 3 and 4 and remove the…
Chrysna
  • 117
  • 1
  • 1
  • 6
-1
votes
1 answer

variable from loop in when statement ansible

I am trying to use a variable in a when statement and ansible pops up a warning like this [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ item.name}}.changed I use a loop first: -…
-1
votes
1 answer

In Ansible, how can I use different template substitutions based on a variable value?

I have a template of a system.d service script that I get filled using Ansible playbook. The template includes experssion [Service] Environment="JAVA_OPTS=-Djava.net.preferIPv4Stack=true -Denvironmentname={{environment_name | default('NOT_SET')…
onkami
  • 8,791
  • 17
  • 90
  • 176
-1
votes
1 answer

How to create dynamic files?

i´m trying to rename ethernet-interfaces on Linux. Each interface with the name enp0s* have to be eth*. First, i create udev-rules for renaming. that works fine. Secondly i have to create new configuration-files for each interface ( '…
mwester
  • 1
  • 1
-1
votes
1 answer

error while setting a fact or debug a webpage after registering this webpage in the get_uri module in Ansible

I have a problem every time while setting a fact for a registered webpage the error is : u'redirected': False}]}: template error while templating string: unexpected char u'&' at 1238 The Playbook like: - name: check webpage uri: url:…
-1
votes
1 answer

from json response uri - how to extract the json keys and values and validate them using ansible json query filter?

Using ANSIBLE: I am getting the json response from url and priting the response but unable to print the particular keys/values. (please see the json response) in my script i would pass Service, so i want to print only particular version of a…
ryan1506
  • 175
  • 1
  • 2
  • 17
-1
votes
1 answer

Parsing tabular data in ansible

Trying to parse route information in ansible to something like below. What's the right way to do [ { "destination": '10.110.2.192', "gateway": '10.110.0.129' "interface": 'eth2' }, { "destination":…
-2
votes
0 answers

ERROR! A worker was found in a dead state in Ansible

I am trying to process around 6000+ dictionary lists in ansible using a small play. The execution is getting stopped in the middle with an error ERROR! A worker was found in a dead state. I have noticed that the memory usage was going up gradually…
Vinny
  • 302
  • 2
  • 11
-2
votes
2 answers

ERROR! the role Users/xxxx/ansible/roles/basic_install' was not found

i am running an ansible playbook, but it won't find my defined roles. I get the following error: ERROR! the role 'Users/xxxx/ansible/roles/basic_install' was not found in…
-2
votes
1 answer

Ansible Tower: 'extra_vars' with multiple variables are ignored when running with curl in cmd

Can some one tell how to pass multiple extra_vars variables from the command line which will run the Job Template in Tower? I've followed Ansible documentaion…
-2
votes
2 answers

Ansible: Need help n printing msgs one by one without /n ..I have given the code and the current output n the description

Need help from the output: Below line from the output need to be printed line by line without \n..plz help..code and actual output pasted with this post "msg": "19:19:11.445 UTC Thu Jul 07 2022\n1657235951 \n1657235051 \n19:04:11 EDT Thu Jul 07…
-2
votes
3 answers

How to print date in Ansible template module?

How to print the present date when the Ansible Jinja2 Template is run? My Jinja2 template is Today date is date +%Y-%m-%d When I run the task it is simply copy pasting the same line, but I want todays date to be printed in the destination file
vtr
  • 11
  • 6
1 2 3
42
43