I like that idea.

<rant>
Right now we're in a transition phase because I've inherited a horrible
Puppet configuration that does unspeakably stupid/evil things.  I actually
have a rudimentary inventory script that polls puppetdb - eventually I'll
put that monstrosity to rest, but for now it's convenient.  Right now I
still need to pass in the deploy_env variable because some configurations
require it and I haven't gotten around to having the inventory script
define them, but once that's in place I'll definitively go with your
suggestion and make environment-specific inventories.
</rant>


On Tue, Jun 24, 2014 at 12:08 PM, Michael DeHaan <mich...@ansible.com>
wrote:

> "
> - hosts: [ '{{ deploy_env }}-bal' ]
> "
>
> This is gross and I would recommend not doing this.
>
> Instead consider seperating your different environments into different
> inventory files (-i production), and having the host group just named "bal"
> in this case.  You can still put nodes in different groups and keep your
> group_vars/ and host_vars/ directories all together.
>
>
>
>
> On Tue, Jun 24, 2014 at 11:13 AM, Claus Strommer <claus.spit...@gmail.com>
> wrote:
>
>> d'oh!  I should have known that.  Thanks a bunch!
>>
>>
>> On Tue, Jun 24, 2014 at 11:05 AM, Michael Peters <
>> michael00pet...@gmail.com> wrote:
>>
>>> When inside the {% %} part you are inside of jinja and don't need
>>> special syntax to tell it that your using jinja variables. Something
>>> like this should work:
>>>
>>> {% for host in groups[deploy_env + '-web'] %}
>>>     server {{ host }} {{ host }}:80
>>> {% endfor %}
>>>
>>> On Tue, Jun 24, 2014 at 10:48 AM, Claus Strommer
>>> <claus.spit...@gmail.com> wrote:
>>> > Hi there,
>>> >
>>> > I have a play with a role that creates a load balancer template.  I've
>>> > successfully tested it in my dev environment, using
>>> >
>>> >
>>> > {% for host in groups['dev-web'] %}
>>> >     server {{ host }} {{ host }}:80
>>> > {% endfor %}
>>> >
>>> >
>>> > the 'dev-web' group is defined in my inventory, as well as 'stage-web',
>>> > 'prod-web', etc.  What I'd like to do is change this template so that
>>> it can
>>> > be used in any environment.  I am already passing a parameter upon
>>> calling
>>> > the play,  --extra-vars "deploy_env=dev".  In the play itself I can
>>> use this
>>> > variable to determine on which balancer the template gets applied, by
>>> using
>>> > something like this:
>>> >
>>> >
>>> > - hosts: [ '{{ deploy_env }}-bal' ]
>>> >   serial: 1
>>> >   vars_files:
>>> >   - /var/lib/ansible/vars/{{ deploy_env }}.yml
>>> >   roles:
>>> >   - role: "haproxy-webbal"
>>> >
>>> >
>>> > However, if I try something similar in the template, e.g.
>>> >
>>> >
>>> > {% for host in groups['{{ deploy_env }}-web'] %}
>>> >     server {{ host }} {{ host }}:80
>>> > {% endfor %}
>>> >
>>> > I get this error:
>>> >
>>> >
>>> > fatal: [stage-webbal-06.aws.primal.com] => {'msg': "One or more
>>> undefined
>>> > variables: 'dict object' has no attribute '{{ deploy_env }}-varnish'",
>>> > 'failed': True}
>>> >
>>> >
>>> > It seems that {{ deploy_env }} is not being expanded, and it's being
>>> taken
>>> > as a literal.  Is this because it's within the {% %} section?  If so,
>>> then
>>> > what is the correct syntax for doing this?  Alternatively, is there a
>>> > cleaner way to approach this?
>>> >
>>> >
>>> >
>>> > --
>>> > 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 ansible-project+unsubscr...@googlegroups.com.
>>> > To post to this group, send email to ansible-project@googlegroups.com.
>>> > To view this discussion on the web visit
>>> >
>>> https://groups.google.com/d/msgid/ansible-project/CABkDv%2B5o4bLiUiNgr-UxP9P8hWpe0SxkhPvhb-T25VrErrMvkw%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 ansible-project+unsubscr...@googlegroups.com.
>>> To post to this group, send email to ansible-project@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAJQqANcG1mjVJXe%2BtR9e6ssk1mivcvtdFce5tfWns4ydOnFrgg%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 ansible-project+unsubscr...@googlegroups.com.
>> To post to this group, send email to ansible-project@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CABkDv%2B6vkXOH3_aMgfm8TCkgXCxZW9%3DyAuKA6m88QEBQDf78Kg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/ansible-project/CABkDv%2B6vkXOH3_aMgfm8TCkgXCxZW9%3DyAuKA6m88QEBQDf78Kg%40mail.gmail.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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzE-ac358mHiq7ejr6-fW-sxAvH-7xaonK97iBa34D1CA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzE-ac358mHiq7ejr6-fW-sxAvH-7xaonK97iBa34D1CA%40mail.gmail.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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CABkDv%2B536OZNaC-m1A3mjVH_RNBbPRTXMwXhXz1-jfetuUsoMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to