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
-1
votes
1 answer

Ansible template error while templating string : unexpected char '@' in email

I'm using Ansible to get a list of user emails from an API and I want to loop over them. This is the json response I get from the API: "users": [ { "email": "email1@email.com", "id": 1, "is_admin": true }, { "email":…
RabbitG
  • 103
  • 1
  • 8
-1
votes
1 answer

Why is a variable not passed to a template?

I have the following task in one of my roles: - name: Moodle--{{ moodle_domain }}--Apache--Virtual Host--Configuration-- Copy become: yes loop: - src: ../templates/moodle.test.conf.j2 dest: /etc/apache2/sites-enabled/{{ moodle_domain…
Geoffrey
  • 5,407
  • 10
  • 43
  • 78
-1
votes
1 answer

Ansible tower survey transforming survey string values

I currently pass parameters to my script which an ansible tower job template/role calls. In order to make it more user friendly, I have decided to use a survey to do this. The script takes on filenames as parameters. The script accepts the…
user3535468
  • 145
  • 13
-1
votes
1 answer

referencing dictionary variable value in ansible task

Team, I have a task where am trying to reference value from a dictionary defined in my values file. but getting below error, any hint? am doing this exercise to use this reference in my other tasks later but first debug step itself is failing. I…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
-1
votes
1 answer

How do I add individual server with individual user in ansible playbook?

For example we have 5 servers and 5 users We need to add individual user to individual server through Ansible playbook. I have written playbook but it is adding all 5 users in all 5 servers. But I need to add user1 in server1 and user 2 in server2…
-1
votes
1 answer

how can we schedule a task to update patching in windows servers through ansible?

we have close to 6 thousand windows servers every month to update them to patching and certain products .we are looking for a solution to automate there updation through ansible without using ansible tower/awx. Please can anyone suggest how this can…
-1
votes
1 answer

How to add variables with command line in ansible?

i have to playbook for tower-cli command, which will create credentials with custom credentials type. - name: Create a valid SCM credential from a private_key file shell: cmd: tower-cli credential create --organization "Default" --name…
-1
votes
1 answer

AnsibleUndefinedVariable: No variable found with this name: region1a"}

I want to get the output of information after comparing whether the region is the capital? Help me figure out how to use "lookup" correctly? {% if capital == lookup('vars', item) %} yes {% else %} no {% endif %} or {% if capital.action == {{ item…
Alex alex
  • 116
  • 1
  • 1
  • 7
-1
votes
1 answer

Ansible: how do I concatenate attributes of dictionaries from a list?

Suppose I have this list: hosts: - {"ip": "1.2.3.4", "hostname": "www.example.com"} - {"ip": "42.42.42.42", "hostname": "www.wikipedia.com"} I want to obtain a string like this (to put it into a template): '1.2.3.4,42.42.42.42' It's similar to…
-1
votes
2 answers

ansible create multiple templates each having incremented var

ansible version: 2.4.2 I would like to create multiple templates with a variable the increments each time. For example I want to generate multiple prometheus config files, having every sequential port incremented by 1 (int). So lets say I want to…
New2Python
  • 325
  • 1
  • 4
  • 17
-1
votes
1 answer

Ansible: How to create nested dictionary using Jinja2

Here is the output. "result.containers":[ { "Image":"ca.docker/webproxy:1.0.0", "Names":[ "/customer1" ] }, { "Image":"docker.local/egacustomer:1.0.1", "Names":[ "/registrator" ] } ] I'm trying to get the following output…
Sara James
  • 133
  • 1
  • 14
-1
votes
1 answer

how to get specific attribute value from stdout json in ansible

instance_tags.stdout output would look like Expected output of fallowing snippet is App Server-Development - name: get instance tags win_shell: aws ec2 --region us-east-1 describe-tags \ --filters "Name=resource-id,Values={{instance_id}}" …
-1
votes
1 answer

ansible template use variable and string

I am trying to fill an ansible variable with: "docker-ce" if on RedHat "docker" otherwise the following works, but is not very clean: docker_edition: 'ce' docker_package: docker{{ "-" if (ansible_os_family == "RedHat") else "" }}{{ docker_edition…
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
-1
votes
2 answers

ansible not identifying yq processor

Team, in my playbook am invoking yq in shell module but its complaining of path. can anyone help please? I have already tested manually yq and jq are available. cat $HOME/.kube/config/cluster-user.kubeconfig | yq…
AhmFM
  • 1,552
  • 3
  • 23
  • 53
-1
votes
1 answer

How to get keys which value is in nested dictionary

Summary: I have nested dict like in example and i want to loop over it. For every "item" i want to have nested keys and value f.e. Input python: lint: where: 'here' Output: python.lint.where: 'here' Why i need it: I'm creating role for…
Farfax
  • 3
  • 1