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

Generate files from Ansible templates without executing plays?

I'm trying to construct an Ansible template file for my playbook and it takes a certain amount of trial-and-error to figure out the correct template variables the template (.j2) file requires. Is there any way to run Ansible so that it will…
Jim
  • 13,430
  • 26
  • 104
  • 155
2
votes
1 answer

How to set concatenated string variable in Ansible template based on a condition

I need to create a string in a template that can change between hosts, and it needs to be in the form of: "cores": "0,1,2,3" And the reason the string is "0,1,2,3" in this example is because the host has 4 processor cores. So I got stuck with…
Vadimski
  • 43
  • 3
2
votes
1 answer

Commenting a block in Ansible

I'm trying to automate some deployments and I need to comment out some configuration, which essentially comprises of a full block. Is there a way to comment a particular block of code/configuration via ansible playbook?
hellodk
  • 316
  • 4
  • 11
2
votes
1 answer

How to make this ansible jenkins script idempotent, when jenkins is rewriting its configuration?

I've a got an ansible playbook to deploy jenkins, where the jenkins config.xml jinja2 template file contains this snippet for AD authentication:
guido
  • 18,864
  • 6
  • 70
  • 95
1
vote
1 answer

Using Ansible to dynamically set a variable in a configuration file from a static config file

I'm trying to use Ansible to automate a variable in a configuration file. I have a template config file that contains this line "config_version={{osVersion}}" This playbook gets ran against RHEL 7 and 8 machines, ideally, I'd like ansible to get the…
1
vote
1 answer

Convert an integer variable to a `first_digit.second_digit` format

I want convert an integer variable into a specific string format. This integer (for example: 56, 71, 80) needs to be converted into a string formatted first_digit.second_digit (for example 5.6, 7.1). How can I do this? I tried a mixture of Python…
1
vote
2 answers

How to set conditions on an Ansible variable

I need to restrict a variable vm_name, in my playbook, to 15 characters, [0-9], [a-z], [A-Z], -_, no special characters like #$%*&. How can I achieve this? - name: Set Vars conditions hosts: localhost vars: vm_name: "abcdefgh12_12-0" …
southwind
  • 29
  • 7
1
vote
1 answer

How can I call with_items task registered output in another with_items task?

I'm trying to create a playbook that will lookup the AWS ARN for an SSL certificate for each of our clients and then use the results with a template to update a custom dictionary. tasks: - name: Find ARN shell: aws acm list-certificates…
Daynesuke
  • 13
  • 2
1
vote
2 answers

Ansible create a list from a loop inline

I have a playbook that goes like this: - name: Install php extensions ansible.builtin.apt: pkg: - php{{ php_version }}{{ item.pkg_extension }} loop: - { pkg_extension: -mysql } - { pkg_extension: -bz2…
siryx
  • 139
  • 1
  • 2
  • 12
1
vote
1 answer

The conditional check 'template is boolean' failed. while using the ansible assertion module

Here's my playbook. - name: "Verify if the 'template' boolean has been set ?" assert: that: - template is defined - template is boolean fail_msg: "'template' must be defined and be present as a boolean" and i got…
1
vote
0 answers

What exactly does the vmware_guest attribute is_template do? -How to use it

I'm trying to use Ansible's vmware_guest module to set a well configured Windows VM as a template via the is_template attribute with the hopes of preserving all configurations of the administrator profile when other VMs are templated from this well…
GlennRA
  • 57
  • 3
1
vote
1 answer

Combine importing a playbook and a role inside a block

I have the following playbook: --- - import_playbook: myplaybook.yml when: - env_tag == 'azure' - my_var is defined - hosts: myserver gather_facts: no ignore_errors: True roles: - role: execute-script vars: …
fr0zt
  • 733
  • 4
  • 12
  • 30
1
vote
2 answers

Simplify the templating of Oracle configuration file based on a dictionary

I am trying to use a template which generate the config file containing tinformations like the hosts, port, username, password, ... I want to use one template and pass the tag in the template task, so the template will pick variables which are…
1
vote
1 answer

Ansible Loops in query Module

Hi I have a requirement to read the content of all the files of specific directory and pass the content to a variable. - name: Generate logs hosts: appserver vars: logs_dir: /properties logs: {} tasks: - name: Read log config…
1
vote
2 answers

How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

I want files in the src directory to copy to the dest directory but I don't want the files with the same name to copy over. Does anyone know how I can do that? - name: Copy files but not the ones that have the same name copy: src: