Small edit, the very last line of code should be:
system_packages: "{{ webserver_packages + system_packages_copy }}"


On Wednesday, April 8, 2015 at 3:21:17 AM UTC-4, Tom Connors wrote:
>
> Please forgive a question from a newbie going about things in what is 
> almost surely the wrong way.
>
> I've got two groups, "webservers" and "dbservers", which are the same 
> machine in dev and different machines in production. I've defined the 
> provisioning for each group in terms of roles, so it looks something like:
>
> - hosts: webservers
>   roles: 
>     - nginx
>     - nodejs
>     - n-number-of-other-roles-from-ansible-galaxy
>     - webservers
>
> - hosts: dbservers
>   roles:
>     - postgresql
>     - n-number-of-other-roles-from-ansible-galaxy
>     - dbservers 
>
> My problem is that the nginx, nodejs, postgresql, and other roles I didn't 
> write might require system packages I haven't installed yet, so I'd like to 
> have a "common" role that all hosts use first that installs the packages. 
> This role would refer to a variable "system_packages" and apt-get install 
> all the packages in that list. In production, I can simply use group_vars 
> for the two groups, but in dev, I can't do that quite as easily because 
> both roles are active at once, so one of them will have their 
> "system_packages" overwritten. My idea for a workaround was to define 
> system_packages as being either the current value of system_packages or an 
> empty list, concatenated with the role-specific packages list. In code, it 
> looks like (roles/webservers/vars/main.yml):
>
> webserver_packages: 
>     - curl
>     - tmux
>
> empty_list: []
>
> system_packages_copy: "{% if system_packages is defined %} 
> {{system_packages}} {% else %} {{empty_list}} {% endif %}"
>
> system_packages: "{{ webserver_system_packages + 
> webserver_system_packages_copy }}"
>
> This fails because of the indirect self-reference by the system_packages 
> variable. Is there a workaround for this behavior? Or is there some better 
> approach for what I'm trying to do?
>

-- 
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/89864ae0-17ac-4e0f-9cdc-639453025e3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to