I'm doing the same thing. The way I solved it was to have an
base-nginx role that defines things like handlers and useful vars:
awesomesauce:$ cat roles/base-nginx/handlers/main.yml
---
- name: bounce nginx
service: name=nginx state=restarted
awesomesauce:$ cat roles/base-nginx/defaults/main.yml
---
nginx_confd: /etc/nginx/conf.d
and then the actual functional roles 'autoload' base-nginx
using the 'meta' feature.
awesomesauce:$ cat roles/imagestore/meta/main.yml
---
dependencies:
- { role: base-nginx }
Saves a lot of typing:
awesomesauce:$ cat roles/imagestore/tasks/main.yml
---
- name: create imagestore docroot
file: name={{imagestore_dir}} mode=0755 state=directory
- name: setup an nginx vhost for serving images
template: src=.{{nginx_confd}}/imagestore.conf.j2
dest={{nginx_confd}}/imagestore.conf
mode=0444 owner=root
notify: bounce nginx
awesomesauce:$
On 7 May 2014 21:35, Strahinja Kustudić <[email protected]> wrote:
> 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.
--
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/CAK5eLPRS3yzm-zEKpw4zvhmNBOR9S-jrtTn58tCvOUAS4vyewA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.