Hi, This is similar to declaring global variables each time before making a function call. I may be wrong but I look at templates similarly. Today you can't pass any arguments when making a call, only rely on global variables available in a play/role.
If a template is rendered within with_dict <https://github.com/evgeny-goldin/playbooks/blob/bab9d8d4ebb6a9d039333f770f79171787021631/playbooks/roles/test-repo/tasks/main.yml#L21> loop - it ends up <https://github.com/evgeny-goldin/playbooks/blob/7a4ce25e0a3bf9edbb0150d1483861ba3c59a0d3/playbooks/roles/test-repo/templates/Simulation.scala#L8> using {{ item.key }} and {{ item.value }} (yuk!) rather than simpler names, passed into a template on each iteration. So templates are attached to variables naming in a play/role and *aren't self-contained*, like a good old function. Any time variable names are changed in a play/role - template needs to be updated as well. It would be so much cleaner to say "This template needs variables 'user' and 'account' to render, pass it in". Have a look at Chef: http://docs.chef.io/templates.html template "/etc/sudoers" do ... variables({ :sudoers_groups => node[:authorization][:sudo][:groups], :sudoers_users => node[:authorization][:sudo][:users] }) end What is cleaner to use in a template - "sudoers_groups" or "node[:authorization][:sudo][:groups]"? Not to mention what happens if the same template if rendered in different contexts where, say, node[:authorization][:sudo][:groups] is something else. Ansible answer to that will be - global "set_fact" for *every* variable before "template" call. -- Warm regards, Evgeny evgenyg.io On Wed, Jan 21, 2015 at 4:01 PM, Brian Coca <[email protected]> wrote: > Not sure why you don't just set the vars at play level, they would be > directly accessible by the template. > > > -- > Brian Coca > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/xO4mnkU9k-E/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAJ5XC8nkng6KFoPO2oxFPeSJNJ0V%2B0Nyo7Y_6kKx0CtKLqH8Hg%40mail.gmail.com > . > 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/CAKCoQxQN-02t6Q%3D2f3sO31XciZ1dGCDA1NDJKHD3k-jCbMh4oA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
