0

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?

4

1 回答 1

2

Jinja2 中包含的语法如下:

main ()
{
  {% include main_body %}
}
于 2016-10-28T14:57:06.923 回答