What do double curly braces ({{) do in YAML files (how is Ansible used)?

I am new to Ansible and trying to understand the YAML file. That I do not understand this fragment of the line - file: dest={{ '{{' }} docroot {{ '}}' }. Can someone explain to me what these braces do? {{''}} '?

- name: Create Web Root

    when: nginxinstalled|success

    file: dest={{ '{{' }} docroot {{ '}}' }} mode=775 state=directory owner=www-data group=www-data

  notify:

      - Reload Nginx
+4
source share
2 answers

Ansible uses the jinja2 template

{{ }} used to evaluate the expression within them from the passed context.

So, {{ '{{' }}evaluates the string{{

And the while expression is {{ docroot }}written to the template, where there docrootmay be another template variable

refer to https://docs.ansible.com/ansible-container/container_yml/template.html for more details.

+3

YAML Ansible documantation, .

, {{ variable }}. ( ), . :

satchmo: {name: Louis Armstrong, music: Jazz, instrument: Trumpet}

, Jinja Template Designer Documentation. Jinja YAML, , Ansible.

{% ... %} for Statements
{{ ... }} for Expressions to print to the template output
{# ... #} for Comments not included in the template output
#  ... ## for Line Statements
+1

Source: https://habr.com/ru/post/1673889/


All Articles