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/5bd13f5a-d9d9-4d97-92ab-210b7b2d3e58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to