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

Simplest non-shell way to confirm set of mount points exist with custom minimum size for each

ansible_mounts is an array of dictionaries, like so - "ansible_mounts": [ { "device": "/dev/mapper/vg_centos67template-lv_root", "fstype": "ext4", "mount": "/", "options": "rw", …
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
0
votes
1 answer

Jinja2 variable out of scope

I've the following template: {% set rotator = 1 %} {% for idx in range(1, count|int + 1) %} {% if rotator == 4 %} {% set rotator = 1 %} {% endif %} { "id": "{{ '%02d' % idx }}", "value": "{{rotator}}" }, {% set rotator = rotator + 1 %} {%…
Mazzy
  • 13,354
  • 43
  • 126
  • 207
0
votes
1 answer

Unable to extract an EC2 public_ip using Ansible after provisioning

I'm running an Ansible play to provision an EC2 instance, but I am unable to extract the public_ip parameter. Here's the play: --- - name: Launch the new EC2 Instance local_action: module: ec2 group_id: "{{ webserver_firewall.group_id }}" …
rahuL
  • 3,330
  • 11
  • 54
  • 79
0
votes
1 answer

How to generate json files in the same task with templates in Ansible

I need to get JMX metrics from the Hazelcast product. I have created a Logstash process that connects to the JMX port. This process has to read a json where is the information of the hostname, port, cluster, environment, etc of Hazelcast JMX. I need…
0
votes
1 answer

Ansible dynamic Value substitution

I am bit new to Ansible and writing an ansible playbook with template.My template has property as below . hostname: {{ ansible_fqdn }} --> This is my target machine hostnames port: ??? Port will vary here. For host1 it will be 7800 and for host2 it…
Shashi
  • 2,686
  • 7
  • 35
  • 67
0
votes
1 answer

Ansible: Implementing mapping algorithm for producers to consumers

So, the scenario is I have producers and consumers in ratio 7:1, and I want to have a consistent and deterministic multilple mapping b/w the producers and consumers in my service. List of consumers is provided in the config to each of the producer,…
ks2bmallik
  • 184
  • 3
  • 18
0
votes
1 answer

change job type of an executed ansible tower job from check to run upon rerun

In the continuous delivery step of my application, I want Jenkins to invoke the ansible tower job (through tower cli) in job type check. Once the devops team decides to release it, I want them to just change the job type to "run" so that the actual…
0
votes
1 answer

changing values directly on the destination system instead of copying file from the source

using ansible looking for some idea for changing values directly on the destination system instead of copying files from source. example: I have many files in tmpl format on the destination system and would like to change the values related to this…
0
votes
1 answer

Is it possible to use and ansible-fact with the with_dict module?

I'm trying to write a role to configure a keepalived cluster. I was hoping to pass unique info into the a template based on the IP of the target box. In this scenario: Server A is 192.168.1.140 and Server B is 192.182.1.141 and the VIP would be…
0
votes
1 answer

Ansible advanced variable parsing

I'm new to Ansible an thus this question may seem silly to more advanced users, I'm not sure if it's possible to do what I'm asking since Ansibel is very limited when it comes to loops and conditionals. I'm performing tasks on a Virtual Connect…
MMT
  • 1,931
  • 3
  • 19
  • 35
0
votes
1 answer

Is possible define a var at run-time and use it to access another var?

I'm not sure that this is possible. I want to define a var at run-time and use it to access another var(defined in file,playbook..). defined at run-time : typeConfig (possible values: "in_config" or "out_config") defined in playbook: in_config: …
Nabidul
  • 16
  • 3
0
votes
1 answer

Jinja2/Ansible Comparing HostVars Values In A Template

I am trying to compare the values of 2 inventory file based hosts' hostvars magic variables in an Ansible Jinja Template. The asking is to basicallyensure that an item is included in the resulting template output, only if the IP addresses of 2 hosts…
NAF
  • 322
  • 5
  • 11
0
votes
2 answers

Add up Ansible variable in Jinja2 template

I have this vars file: addvlan: - vlan: pruebavlan address: 192.168.10.0 mask: 25 gateway: ???? tag: 1917 And I have this JSON which use the vars of above vars: "address": "{{address}}", "mask": {{mask}}, "gateway":…
user6593995
0
votes
1 answer

Ansible Jinja2 for printout produces duplicate result

Ansible version 2.2, Mac OS X El Capitan I'm trying to generate list of port mappings. When i run code like that --- - hosts: [localhost] sudo: True pre_tasks: - debug: var: "{% for id in range(100,102) %} '{{ id…
AlexS
  • 927
  • 4
  • 16
  • 29
0
votes
1 answer

Ansible: is it possible to Jinja2 filter the content picked up by lookup()?

I'm sending a REST API query using Ansible uri module. The body content is picked up from a file: body: "{{ lookup('file',mp_config_path + item.file) }}" There are some variables in my file - is it possible to tell ansible to run Jinja2 filters on…
Misko
  • 1,542
  • 2
  • 19
  • 31