{{ ansible_interfaces }} will be available in the template and you'll be
able to loop over it in the template logic.Do not use with_items on the template task, as this will result in writing the file N different times, and will not do what you want. On Tue, Aug 26, 2014 at 11:23 PM, Sergei Antipov <[email protected]> wrote: > example: > - name: create /etc/network/intefaces file > template: src=xxx dest=xxx > with_items: ansible_interfaces > when: item | match("eth*") > > and in template I need: > .... > slaves eth0 eth1 eth2 ethX > .... > > вторник, 26 августа 2014 г., 19:47:21 UTC+7 пользователь Michael DeHaan > написал: >> >> I'm not sure what you mean you say "use items from the task condition", >> but you can in fact use conditionals with your template. >> >> Take a look at the Jinja2 documentation, and you'll see things like >> >> {% if x %} >> >> {% else %} >> >> {% endif %} >> >> and these can be put in your .j2 files. >> >> I might have misunderstood the question. >> >> >> On Tue, Aug 26, 2014 at 6:40 AM, Sergei Antipov <[email protected]> >> wrote: >> >>> Hello. >>> >>> Please tell me how I can use items from task condition in template. Or >>> other method, how I can decide my probled. >>> goal: I have a template for /etc/network/interfaces file. I want to set >>> up bond interface, which contains the parameter "slaves XXX XXX XXX", where >>> XXX - name of interface. >>> I want use only interfaces, which name match ethX regex, for example >>> "slaves eth0 eth1". >>> How I can do this template with ansible, maybe I should use >>> ansible_interfaces variable or should use shell for register intefaces >>> names? >>> >>> -- >>> 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/de6d2241-7bc0-493d-86b4- >>> be7974c05941%40googlegroups.com >>> <https://groups.google.com/d/msgid/ansible-project/de6d2241-7bc0-493d-86b4-be7974c05941%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > 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/08d7c7b0-7e3f-49be-9ab5-62cf94bc9b40%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/08d7c7b0-7e3f-49be-9ab5-62cf94bc9b40%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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/CA%2BnsWgyafPe_3bs9OiNOoctcGGkbzO11rx1h98mZYD_frANzdg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
