My nginx role uses similar principle, but instead of creating a separate
template file for each role, I have one giant, general nginx server
template and pass configuration i want for a particular role using hash
variables with lists and hashes inside.

Nginx role: https://github.com/ginas/ginas/tree/master/playbooks/roles/nginx
Example configuration for ownCloud instance:
https://github.com/ginas/ginas/blob/master/playbooks/roles/owncloud/vars/main.yml
Example configuration for phpMyAdmin instance:
https://github.com/ginas/ginas/blob/master/playbooks/roles/phpmyadmin/vars/main.yml


2014-05-07 22:35 GMT+02:00 Strahinja Kustudić <[email protected]>:

> 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<https://groups.google.com/d/msgid/ansible-project/228baad4-9076-4109-ab4c-9d43f75e860d%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 [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/CAEnKK1x2L-DMtG0gOyY7n6MuPvb8bSk9Z%2BiMEbo6pFEbBqjvoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to