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

error while putting mapped values in arguments in ansible playbook

Good Day!! I was searching for some solution on my ansible playbook where I want to run an application inbuilt .sh script with arguments and corresponding mapped values. Below is the command which I can successfully execute in terminal window. I…
0
votes
1 answer

Unable to get group ipv4 address in ansible with template

I'm trying to enumerate my eth0 address (set to default, because I read somewhere that eth0 is not always available..). In my template I attempt calling it from the group like so... [Unit] Description=Kubernetes Kube…
ehime
  • 8,025
  • 14
  • 51
  • 110
0
votes
1 answer

Variabalizing a file line with Ansible?

I'm looking to put an ip in variables to pass into a template, unfortunately something somewhere is messing up with registering the variable? - name: Get Controller[0] ip command: "cat {{ controller0 }} |grep -A1 controller0 |tail -1 |awk…
ehime
  • 8,025
  • 14
  • 51
  • 110
0
votes
1 answer

Browsing JSON variable in Ansible

For some reasons, I'm not allowed to use jsqon_query with Ansible, I'm trying to reach stdout element in a results list in a variable resulting from a shell call. The JSON variable is saved this way : "request": { "changed": true, "msg":…
Waldo
  • 189
  • 1
  • 8
0
votes
1 answer

Using vars together with template in Ansible

I'm a little bit confuse when trying to use the predefined vars into my template. My purpose is I want my template.xml file will contains the right information already defined in the vars yaml file. For example, for each namevm will have each…
0
votes
1 answer

Ansible - how to make task fail based on specific output

Hi I have a task which requires ftp a file from remote box to ansible controlled machine.I am using expect based FTP,so want the ansible to fail if file does not exist on the remote box.Following is my code. I am using a register variable.But i dont…
Suzanno Hogwarts
  • 323
  • 2
  • 3
  • 12
0
votes
1 answer

How do I extract a value for a certain key in json output in Ansible into a list?

I have the following data structure set as a fact at the end of an ansible task. I am trying to extract the SITEID's into a list. "myoutput": [ { "ID": "ZG5zLmhvc3QkLm5vbl9ETlNfaG9zdF9yb290LjAuMTUzNzE1MTcwNzgxNC5oZWxsbw", …
user1768233
  • 1,409
  • 3
  • 20
  • 28
0
votes
1 answer

Overriding ansible config with extra vars

I define a custom ansible.cfg, and export it as below in the export ANSIBLE_CONFIG="../aws_ansible.cfg" when I run it, this is picked up but when I pass the inventory as an arg, it fails to recognize the arg or take precedence although there is no…
hackmabrain
  • 457
  • 1
  • 6
  • 21
0
votes
1 answer

Adding dynamic value into jinja2 expression

As an example I have an ansible playbook that looks like this: --- - hosts: localhost vars: filename: "me-0.0.1" tasks: - name: get filenames find: paths: /home/vagrant/test patterns: 'me\-[\d]\.[\d]\.[\d]\.jar' …
krystan honour
  • 6,523
  • 3
  • 36
  • 63
0
votes
1 answer

Load Nested Files With host_group_vars Plugin From Custom Locations

I am trying to create ansible role to generate kubernetes deployment with ansible. I want all customization to be stored in var files and be loaded automatically during group_vars and host_vars loading. I end up with following nested structure of…
Vladimir
  • 615
  • 5
  • 12
0
votes
2 answers

Referencing Ansible Variables

I am new to Ansible and I am attempting to work on getting user access under control. I found this playbook from Galaxy: https://github.com/singleplatform-eng/ansible-users I was also reading from this source to help manage different…
Minnow47
  • 1
  • 3
0
votes
0 answers

Ansible: Access set_fact variables across hosts blocks during playbook

[NOTE]: This is not like accessing other hosts' yaml data like described here. This is setting my own variable during execution and want to access it later I am using ansible-playbook to perform some task on 2 vm pools. Assume that I have only one…
Ashwin
  • 993
  • 1
  • 16
  • 41
0
votes
1 answer

Ansible/yaml: If syntax inside the for syntax

Is this possible? I want to decide on which 'dict' for loop will iterate. {% for item, value in {% if source == "cde" %} abc.iteritems() {% else %} def.iteritems() {% endif %} %} item {% endfor %}
0
votes
1 answer

Make ansible ignore variable in template when checking changed state

I need to create a template file that includes a random string. I only need to set this random value once, but it would be nice to re-use the role file to update the output file if static parts of the template get updated. The way I have it running…
user2066480
  • 1,229
  • 2
  • 12
  • 24
0
votes
1 answer

Ansible loops matching on array/dict_list

I have an array like so our_domains: - domain: www.example.com urls: - { path: '/' } - { path: '/test1' } - domain: www.example2.com urls: - { path: '/' } - { path: '/test2' } and in a template I want to match on…
coopz81
  • 35
  • 3