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

ansible: filter one element of the list to string

ansible 2.9.13 Need to add to the remote file string like MyIP = xxx.xxx.xxx.xxx Here is a test template: MyIP = {{ ansible_all_ipv4_addresses | select('match', '^10\.0\.59') | list}} result >cat testfile.txt MyIP = ['10.0.59.100'] Question: What…
Alexander Lanin
  • 375
  • 5
  • 15
3
votes
2 answers

How can I get a comma separated list of firstnames?

This is my list of addresses in a YAML file : addresses: person1: firstname: Maria lastname: Smith person2: firstname: July lastname: Weber person3: firstname: John lastname: Kurt person4: firstname: Simon …
ducato66
  • 53
  • 1
  • 3
3
votes
2 answers

Ansible get hostnames from one group as a variable to another play

Here is inventory file. [abc] host1 host2 [123] host3 And main.yml #play1 - hosts: abc roles: - { role: abc } tasks: ... #play2 - hosts: 123 roles: - { role: 123 } tasks: debug: msg="{{inventory_hostname}}" Basically I…
3
votes
2 answers

Does ansible support modules written in Go?

Ansible supports custom modules written in Python . For execution types which are not local( local mean connection: local & hosts: localhost), ansible ssh's python packages to remote node, for every play. Does ansible support writing modules in…
overexchange
  • 15,768
  • 30
  • 152
  • 347
3
votes
2 answers

Get a list of inventory hostnames

host1: abc host2: xyz host1 and host2 are listed under test-hosts [test-hosts] abc xyz When i debug for inventory_hostnames, i see them like below > TASK [debug inventory_hostname] >…
munna
  • 103
  • 2
  • 9
3
votes
1 answer

How to extract the exact output from stdout.lines in ansible

My Ansible Playbook: #Tag --> B.6 --> - name: Change the Security Realm to CustomRealm from ManagementRealm command: /jboss-as-7.1.1.Final/bin/jboss-cli.sh…
anish anil
  • 2,299
  • 7
  • 21
  • 41
3
votes
2 answers

How can I break the with_items loop based on a condition

I want to break out of the with_items loop based on a condition. That condition for arguments sake is if the stdout of a command is equal to a particular string. Obviously the example below does not work but this is an idea of what I want to do. For…
3
votes
2 answers

Can ansible variables be used to declare hosts in a playbook?

I have a playbook in the format below: --- - hosts: myIP tasks: - name: Install a yum package in Ansible example yum: name: ThePackageIWantToInstall state: present where myIP and ThePackageIWantToInstall are variables. When the…
3
votes
1 answer

Ansible: applying role templates hierarchically

I'm planning to use Ansible to manage a fairly large set of Linux servers with a lot of variation among them. The hosts will be grouped into roles with a hierarchy between them, there's a common role, on which every other depends, child-roles which…
André Fernandes
  • 2,335
  • 3
  • 25
  • 33
3
votes
1 answer

Get a value from ansible uri json request

I'm a noob in ansible and jinja template, and I need to get a value from a uri json result, but I don't know how to do this. I have the uri request below: - name: Busca o id do usuario na Gitlab API uri: url: "{{ gitlab_host_server…
mayconfsbrito
  • 2,085
  • 4
  • 26
  • 45
3
votes
3 answers

Use Dict in Vars with Templates in Ansible

I'm trying to use templates with different sets of variables for each itteration of a determined set of tasks. For example, in one of the tasks I'd like to set specific values for postgres: - name: Define values for postgres-ds template: src:…
Rebeca Maia
  • 438
  • 4
  • 16
3
votes
3 answers

Ansible/Jinja2 How to format a list into fields for my config file?

I have the following and keep in mind I do not know how many ips will be in this incoming variable but I am starting with 2 for simplicity. vars: host_ips: ['10.0.0.100', '10.0.0.200'] I'm trying to format them in a file using a template with…
RedBloodMage
  • 77
  • 1
  • 1
  • 5
3
votes
3 answers

How to ignore jinja2 braces {{}} in j2 template file

I have a j2 file that i want to edit and copy to my remote server (as apart of my ansible play). The file has several 3 variables indicated by braces {{ }}. How can I only target the 2nd variable named {{ bar }} and ignore the other 2 in the file so…
druffin
  • 163
  • 2
  • 15
3
votes
1 answer

Splitting variable not working in Ansible

I am trying to split the variable based on delimiter. How can I achieve it? some_module: {{item}}.split('@')[1] with_items: - git@someversionxxx - gradle@someversionxxx I get following error: list object' has no attribute 'split…
MMA
  • 408
  • 3
  • 7
  • 19
2
votes
2 answers

Complex data structures in Ansible

I am attempting to automate an Ansible playbook that will run specific commands on a Docker container deployed on different servers. For example, I have two VMs (vm1 and vm2 as shown in commands.yml), so, on vm1 I want to run command 1 and command 2…