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

Unable to fit the ansible code in playbook

This is a log file stored in Yaml Format. My job is to find out the hostname which belongs to hostclass ess, which in this case the answer is host002. hostinfo: 'host001': ip: 192.168.43.10 hostclass: 'puppet' 'host002': ip:…
0
votes
0 answers

How to gather debug logs from Cisco routers Device using ansible?

Requirement using Ansible is: > 1.Connect to the router first. > 2.Then push debug commands to the router.(using ansible playbook) > 3.Ansible will wait for few seconds because router will take some time to dump the output on the monitor…
0
votes
0 answers

ansible playbook value starts with jinja2 template and has a colon

I'm running into an issue with with two YAML gotchas at the same time. I've tried a number of variation from around the web to try to get around this with no success. The Task: - name: Mount nfs on cluster1 mount: path: /mnt/nfs_jenkins …
user9295037
0
votes
0 answers

Output hosts from ansible inventory group to a template

I try to fill the ansible (jinja) template with a comma-separated list of all hosts in the group 'lan-msqservers'.
Niko E.
  • 1
  • 1
0
votes
1 answer

Ansible double loop

I have a data list in an yml file. I would like to extract data, using a double loop, like we use to do. This is an example of my list [a,b,c] vm1: -a -b vm2: -a -c vm3: -b This is for a generic deployment…
Kassav'
  • 1,130
  • 9
  • 29
0
votes
1 answer

How to access data from a file upto delimiter in ansible and assign data to a variable and loop playbook according to the variable

I have a file data like below: [prod] product=Admin;Financial;Hrm When I try to access file data I am getting complete line, like Admin;Financial;Hrm but for the first loop I have to take only Admin, and for the second loop I should get Financial…
monu
  • 23
  • 1
  • 8
0
votes
1 answer

ansible passing to a mapped variable

I have an ansible tomcat role defaults/main.yml tomcat_http: port: "8080" protocol: "HTTP/1.1" connectionTimeout: "120000" URIEncoding: "UTF-8" I have another role (app) which uses tomcat role as a dependency and looks like…
harnex
  • 953
  • 1
  • 7
  • 8
0
votes
1 answer

How to pass variable in Ansbile?

Could not find out why variables not being picked up in Ansible 2.3.1.0. File structure: . ├── ansible.cfg ├── group_vars │   └── test1.yml ├── hosts ├── host_vars │   └── test1 ├── roles │   └── install │   └── tasks │   └──…
wzcwts521
  • 15
  • 4
0
votes
2 answers

Strip json object in Ansible if key exists

Say I have a json object like this: { "results": [ { "failed": "no", "data": "another string" }, "failed": "no", "skipped": true } } Is there a way to strip the json of any object that has "skipped" defined in an…
CEamonn
  • 853
  • 14
  • 37
0
votes
1 answer

Ansible: parsing/concatenating output of getent module

I try to set up chroot for sftp users, so that they can see user/group names on ls -l as per this article. To this end I need to get output of getent command and place it into /chroots/{{ user.username }}/etc/passwd file. I try to use Ansible to…
user1876484
  • 610
  • 6
  • 16
0
votes
1 answer

Ansible - combining string with an existing variable to register into another variable

I want to combine a fact set with set_facts with a string variable and register it as a new variable. I think, we cannot register a new variable in an Ansible playbook. So can I use set_facts again to combine a previous set_fact with an existing…
sherri
  • 421
  • 2
  • 9
  • 19
0
votes
1 answer

Generate single configuration for multiple hosts from Jinja2 template

Problem: I've got 2 tasks that are executed sequentially as (expected) given the Ansible nature. As I understand, you can only execute one module per each task. Task 1 - Gather facts information (serials, versions, etc) from network devices. Task 2…
Daniel Macuare
  • 72
  • 1
  • 2
  • 9
0
votes
1 answer

What data type does dictsort produce in Ansible/Jinja2?

Explanation Assuming I have a dictionary mydict set to { "key1": "value1" }: The result of dictsort filter (mydict|dictsort) in Ansible seems to be a list containing another list: [ [ "key1", "value1" ] ] However, when…
techraf
  • 64,883
  • 27
  • 193
  • 198
0
votes
1 answer

Return group and group length using Jinja2 templating

I have an Ansible inventory file, with a group that contains roughly 20 children groups. I want to return the list of children so I started with: {% for group in groups[maingroup] %} {{ group }} {% endfor %} Next, how can I add next to the…
0
votes
1 answer

Jinja templating for Ansible

I have a template that does the following to sudoers: {% for a in cde_admins %} User_Alias CDEADMIN = {{ a }} {% endfor %} And I have the variables defined: cde_admins: - foo - bar I am looking for a way that I can iterate through the loop…
ryekayo
  • 2,341
  • 3
  • 23
  • 51