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
0 answers

Ansible ios playbook to gather IOS runinng config of diferents hosts to files

I'm looking to create a playbook on ansible to gather info of more than 300 hosts and save the info to a file. I get 2 diffente issues, one not being able to save the info to a file and the second issue comes because of telnet connection of some…
0
votes
1 answer

Ansible: getting values from results

I'm having trouble getting variables from ansible. I might be misunderstanding it all, but; I have a play, creating 3 mysql instances that I'd like to get set new root pass from temporary pass in mysql log. I can do it with one instance, but when I…
MSchultz
  • 3
  • 3
0
votes
1 answer

Ansible Jinja2 template for loop

I have two linux servers: - server1: ip: 10.241.55.6, hostname: server1 - server2: ip: 10.242.55.7, hostname: server2 I have created an ansible inventory file named servers with the content bellow: [IC] 10.241.55.6 10.241.55.7 Now I have created…
Bogdan Stoica
  • 4,349
  • 2
  • 23
  • 38
0
votes
2 answers

Include content of ansible template based on value of variable

I'd like to generate and deploy nginx reverse proxy configurations via ansible. In the template, there is a part for intercepting errors (404, 501, etc), this should not be active for ALL the deploys. I'd like to be able to toggle the inclusion of…
maxap
  • 90
  • 5
0
votes
1 answer

getting error while executing ansible command

I'm getting the following output when running an Ansible ping command: [root@test1~]# ansible -m ping 10.95.252.140` [WARNING]: Found both group and host with same name: dev_oip_servers [WARNING]: Unable to load the facts cache plugin …
0
votes
1 answer

How to fix the error 'module' object has no attribute 'UnexpectedResponse' in Ansible playbook

Here is the playbook for your reference: --- - name: Closing notes hosts: XXXX gather_facts: yes tasks: - name: Modify a change request snow_record: state: present table: change_request username: admin password:…
0
votes
1 answer

jinja2 '{% set ... %}' processing in ansible playbook

I don't understand how to use jinja2 templating commands in an ansible playbook. My understanding is that the playbook should be processed as a jinja2 template before execution, but apparently not before the file is parsed as yaml, because using a…
Charles Langlois
  • 4,198
  • 4
  • 16
  • 25
0
votes
1 answer

Using template in complex list variable

I have a var file like below and the two items don't work the same: the first one is treated as a JSON object and I can access its properties, such as script.name, but it's not the case for the second item which seems to be a plain string. How can I…
assylias
  • 321,522
  • 82
  • 660
  • 783
0
votes
1 answer

ansible syntax error to set tag in playbook under roles

Team, I tried several combinations nothing worked. how to set tag under role in playbook? roles: - 3_validations_on_ssh tags: [test] - 3_validations_on_ssh tags: test output: The offending line appears to be: -…
user10724620
0
votes
1 answer

Ansible condition to run specific tasks in a playbook only if host belongs to specific group in inventory file

I created a playbook with 6 different tasks and want to run tasks 1,2,3 only when host is a child of was855node group (e.g. b, c) and tasks 4,5 to run only when hosts is child of was855dmgr group (e.g. a) My inventory…
0
votes
0 answers

How to change nested variables inside a dictionary in ansible (jinja2)

I am currently trying to use the acme_certificate module from ansible to automatically generate a lets encrypt certificate for my servers. Since my service provider doesn't provide a route53 compatible endpoint I had to write my own python script to…
ket
  • 39
  • 1
  • 7
0
votes
1 answer

How do I use Ansible loop register values?

I am trying to grep the process IDs for a process on multiple target hosts and trying to kill that process. What I have so far is this - name: Grep any running process shell: ps aux | grep "[m]ongo*" | awk '{ print $2 }' register:…
RPT
  • 728
  • 1
  • 10
  • 29
0
votes
2 answers

Ansible, pg_hba.conf configuration with IPs from hosts file

I have problem and i don't did i even start correctly. i have hosts file that looks like all: children: application1: children: application1-webserver: hosts: host1.domain.net: host2.domain.net: …
0
votes
1 answer

Ansible jinja2 template with linux command

I am learning ansible. i have written a jinja2 template for looping over a multiple values. However, i get those values from a linux command. - name: fetching port ranges command: ls /apache |grep redis|grep ".pid" | awk -F"_" '{ print $2}'|…
0
votes
1 answer

Ansible How to loop inside the files for templates

Need to loop through the source files one by one for all hosts. - hosts: epson* become: yes tasks: - name: replace id vars: id: abc template: src: epson1.j2 dest: /home/epson.config HOSTS…
suraj shetty
  • 136
  • 1
  • 6