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

Shell module fails but raw module works .. in Ansible

my client machine is 5.11 and python version 2.7 but still it is failing root@00047BLRSANDEEPC:/mnt/e/Ansible-project/Solarwind/systems_swiagent_install/tests# ansible -i hosts all -m shell -a "cat /etc/redhat-release" 10.XX.XX.XX | FAILED! => { …
0
votes
1 answer

How to read a particular part of file in ansible

I have a file which has the following data ! multiply 4 and 5 multiply 5 and 6 ! add 3 to 4 add 8 to 4 ! sub 3 from 6 sub 9 from 5 ! ! div 6 by 2 div 8 by 1 I want to read only add commands from the file. Using lookup plugin I was able to read the…
Noobie
  • 55
  • 1
  • 2
  • 7
0
votes
1 answer

Editing an j2 template using ansible

I have an vendor Ansible playbook given to us and I will need add an new line to the j2 template and tweak the playbook for our env, I will need to edit the template with an line -> retention_days: {{ xyz }} This is how the orginal template looks…
helper
  • 15
  • 1
  • 5
0
votes
2 answers

How can I use a wildcard to include multiple files for using environment variables in Ansible?

I am trying to do a custom install of openedx and I have a bunch of .yml files with environment variables in them inside paths that looks like this playbooks/roles//defaults/main.yml Then, while running a playbook that installs all…
Gaurav Ojha
  • 1,147
  • 1
  • 15
  • 37
0
votes
2 answers

How to fix "Undefind error" while parsing a dictionary in ansible registered variable?

I'm creating some ec2 instances from a specific image, then trying to get a list of disks attached to these instances. The problem is when I try to loop over the registered variable from the create instance task, I got an error I have tried the…
Haitham00n
  • 31
  • 4
0
votes
1 answer

yum module not talking to telnet

I've written a playbook using a tag feature so that I can control the execution of the playbook. The Playbook is correct syntax-wise. ansible-playbook tags.yml --syntax-check Gives no Error However, when I run the playbook, I receive the following…
FM2012
  • 61
  • 1
  • 1
  • 8
0
votes
1 answer

Ansible: Build Command with variables

I would like to build an ansible playbook and at this point I need some help. I have my defaults: variables: module1: true module2: false module3: true module4: true I need now to find out which module key has a true-value and put the key…
sokolata
  • 491
  • 3
  • 7
  • 21
0
votes
3 answers

How to include a dictionary into a k8s_raw data field

I'm writing an Ansible-playbook to insert a list of secret object into Kubernetes. I'm using k8s_raw syntax and I want to import this list from a group_vars file. I can't find the right syntax to import the list of secret into my data…
Sleepless
  • 33
  • 1
  • 7
0
votes
0 answers

How to remove a specific block of lines from prometheus.yml file using ansible?

I have a prometheus.yml config file which have multiple k8s clusters configured for monitoring. Since the servers come and go we need to delete the servers which are deleted from our peometheus.yml config file using ansible. I tried with the…
0
votes
1 answer

Ansible task is failing even with the right syntax

I am learning ansible and i have written a task for LDAP validation. However, when i run the playbook, the task is failing even when the validation is correct. Below is the ansible task which will check for the LDAP password max age - name: LDAP…
0
votes
0 answers

Ansible: incremental append to list vars

I'm configuring a template file in Ansible and I'm having trouble figuring out a way to append values to a list var multiple times. My setup has multiple groups and roles, each of those could have extra values to append to a global list of routes…
André Fernandes
  • 2,335
  • 3
  • 25
  • 33
0
votes
3 answers

group_names and nested variables

I'm having to make multiple changes to my network in a relatively short space of time so to save time I decided to use Ansible. I have multiple types servers in multiple environments so need to iterate across each environment and each type of server…
Ft00msh
  • 101
  • 2
  • 8
0
votes
1 answer

Ansible dictionary not working when we have multiple strings in the list

I have dictionary to loop multiple strings in the list, if I provide 2 or more then it's always reading last value in the list, please suggest me. - set_fact: env_microservice_variable_map: | {% set res = [] -%} {% for…
Vijaya Krishna
  • 35
  • 1
  • 12
0
votes
1 answer

Template with variable variables is there a better way?

im setting up a set of ansible tasks to manage a large amount of system. both for building and setup and ongoing updates. working on the network script tasks and running into issues. the number of interfaces on each box is variable. the number…
0
votes
1 answer

I am unable to fix the ansible playbook

I am trying to write a playbook to create two files .When nested variables are defined. I have got the output but this is not what I expect . I need to create two files with only the variables defines playbook.yml - hosts: all vars: variable: …