Hi,

I need to set values for variable per task. Is it possible at all in 
Ansible?
I have this template:

<VirtualHost *:80>
    DocumentRoot /var/www/{{name}}
    ServerName {{name}}{{domain}}
</VirtualHost>

And I want to call it with specific name and domain parameter without 
modifying the template.
I tried this:

- template: dest=/etc/apache2/sites-available/{{ item }}
            src=templates/virtualhost.j2
  with_items:
    - sitename

But this syntax is not good, because it requires to rewrite template to use 
{{ item }}.
Is it possible to avoid that?

I tried moving the task into separate playbook and invoke it as 
parametrized include.

- include: roles/web/tasks/virtualhost-add.yml name=sitename domain=example.
com

This works until I add a loop with_items.

- include: roles/web/tasks/virtualhost-add.yml name={{item}} domain=example.
com
  with_items:
    - sitename

Now Ansible fails with:

ERROR: [DEPRECATED]: include + with_items is a removed deprecated feature.  
Please update your playbooks.

So, is that at all possible and what is the current best practice for 
templating files in a loop? I thought that the most simple way is to add 
some variables_override parameter to template module.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dcb5622e-dfd2-4d8d-888c-7dc4b673ed6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to