Top "Ansible-template" questions

Use this tag for questions regarding writing and processing Ansible templates, Jinja2 syntax within Ansible, custom filters.

Ansible: get current target host's IP address

How do you get the current host's IP address in a role? I know you can get the list of …

ansible ansible-facts ansible-template
How to use template module with different set of variables?

My use case is the following : I have a template file, and I would like to create 2 different files from …

ansible ansible-template
Passing variables to ansible roles

I have my directory structure as this └── digitalocean ├── README.md ├── play.yml └── roles ├── bootstrap_server │   └── tasks │   └── main.yml ├── create_new_…

ansible ansible-template
How to get the first element of a list from the output of setup module in Ansible?

I received the following data from the setup module: "ansible_nodename": "3d734bc2a391", "ansible_os_family": "RedHat", "ansible_pkg_…

ansible jinja2 ansible-facts ansible-template
Ansible Jinja2 string comparison

I am getting value of variable "env" in Jinja2 template file using a variable defined in group_vars like: env: "{{ …

ansible jinja2 ansible-template
how to append to a list in jinja2 for ansible

Below is the jinja2 template that i wrote to use in ansible. {% set port = 1234 %} {% set server_ip = [] %} {% for ip in …

templates ansible jinja2 ansible-template
How can I test jinja2 templates in ansible?

Sometimes I need to test some jinja2 templates that I use in my ansible roles. What is the simplest way …

ansible jinja2 ansible-playbook ansible-template
Loop dictionary in ansible template

I'm trying to loop a dictionary through an ansible template using jinja2 to create a number of datasources but receive …

ansible jinja2 ansible-template
ansible - delete unmanaged files from directory?

I want to recursively copy over a directory and render all .j2 files in there as templates. For this I …

ansible ansible-template
Ansible, set_fact using if then else statement

I am trying to set a variable in Ansible with set_fact at runtime based upon another variable. If uses …

ansible jinja2 ansible-template