ceving
ceving

Reputation: 23824

How to include a variable file in Ansible?

I have the following playbook:

- hosts: localhost
  tasks:
    - set_fact: main_body="test_main"
    - template:
        src: test_src.j2
        dest: /tmp/test_dest.j2

And the following Jinja template:

main ()
{
  {{ include main_body }}
}

When I run the playbook I get the error:

AnsibleError: template error while templating string: expected token 'end of print statement', got 'main_body'.

How to tell Jinja to include a file, its name is stored in a previously defined fact?

Upvotes: 0

Views: 1169

Answers (1)

techraf
techraf

Reputation: 68469

The syntax for include in Jinja2 is the following:

main ()
{
  {% include main_body %}
}

Upvotes: 2

Related Questions