"Ansible variables seem to have a global scope, because if I set one within
the role it seems to be visible to all roles"

No exactly true for roles.

Ansible variables set in one role are available in roles further down so
you can have roles that describe an environment, but they do have scope.
 In fact, you are guaranteed access to that particular value, without it
being clobbered.

We've been through this a few times today on this list, in fact :)



On Tue, Jul 1, 2014 at 6:56 PM, Marc Abramowitz <msabr...@gmail.com> wrote:

> On Tuesday, July 1, 2014 10:19:16 AM UTC-7, John Anderson wrote:
>>
>> So we configure a pool for all the nodes in the addressbookweb group to
>> listen on nginx port 6014, and then when a request to
>> /addressbook comes into the loadbalancer it routes to that specific pool.
>>  But when we setup the addressbook nodes we also need
>> to configure nginx properly to listen on that port.
>>
>> So we do this by doing:
>>
>>      services[current_role].nginx_port
>>
>> But do access current_role we had to set a variable for *every* role.
>>
>
> How about this?
>
> # roles/anonweb/tasks/main.yml
> { include: ../../../roles/pythonapp/tasks/main.yml, app_role: anonweb }
>
> # roles/addressbookweb/tasks/main.yml
> { include: ../../../roles/pythonapp/tasks/main.yml, app_role:
> addressbookweb }
>
> # ../../../roles/pythonapp/tasks/main.yml
> # do stuff nginx config stuff with {{ app_role }}
>
> Ansible variables seem to have a global scope, because if I set one within
> the role it seems to be visible to all roles (which surprised me as I was
> expecting roles to be more self-contained since they're supposed to be
> reusable, shared on Galaxy, etc.). All roles are referencing the same named
> variable are sharing the same global variable. But the parameterized roles
> and parameterized includes are more akin to parameter passing and so the
> state is not shared.
>
> --
> 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/0cc40dad-47d7-4c98-b1f0-2ba1de053e3f%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0cc40dad-47d7-4c98-b1f0-2ba1de053e3f%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 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%2BnsWgw6hXbOiXjBMbVj9jmFfsNjX5eFuRj_izxX-Crdk%3DoRKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to