I have been using Ansible for a few months now and it has been a blast. I 
think I got the hang of how Ansible works pretty good, but I'm still not 
sure about what is the best way to reuse roles.

Let's take the "nginx" role as an example. We have Nginx installed on a lot 
of servers, but besides the common steps of installing nginx, the 
configuration files are a lot different (some servers only have http, some 
have SSL as well, so they need certificates, different virtual hosts, etc).

What I did is created a variable called *nginx_server_type*, which you set 
to a server name, or group name (which shares the same configuration files) 
and then use it like this:

- name: Copy /etc/nginx/nginx.conf
  template: src={{ nginx_server_type }}/etc/nginx/nginx.conf.j2
            dest=/etc/nginx/nginx.conf
            mode=0644
            owner=root
            group=root
  notify: reload nginx

- name: Copy /etc/nginx/
  copy: src={{ nginx_server_type }}/etc/nginx/
        dest=/etc/nginx/
  notify: reload nginx


Then you need to create directories inside *templates *and *files *which 
are called {{ nginx_server_type }} and put the configuration files in them. 
So basically every time I need a new server, I modify a role by adding 
template and configuration files for that server.

This problem basically comes up for any role which is not the same for all 
servers. Is there a better way to deal with this? How do you do it?

-- 
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/228baad4-9076-4109-ab4c-9d43f75e860d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to