" I think the most elegant way to handle this is to add a new keyword in
the role dependency statement that would allow to override templates and
files on a "common" role by another role that depends on it."

 Adding a new keyword is almost never the answer.

It sounds like the OP just needs to pass a parameter into the role to me.




On Fri, May 9, 2014 at 2:39 AM, 'Petros Moisiadis' via Ansible Project <
[email protected]> wrote:

>  On 05/07/2014 11:35 PM, Strahinja Kustudić 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<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.
>
>
> What you want is very common. I think the most elegant way to handle this
> is to add a new keyword in the role dependency statement that would allow
> to override templates and files on a "common" role by another role that
> depends on it. So, in your case you could create an "nginx_common" role as
> well as several "nginx_sometype" roles that would depend on "nginx_common"
> role and provide any templates/files to override the ones in the
> "nginx_common" role. That way you do not have to "pollute" your
> "nginx_common" role directory with templates/files that are not actually
> "common" or conflict with each other. Instead, you keep separate
> "nginx_sometype" roles and each one of them can provide its own set of
> templates/files that will override the ones in "nginx_common" role "on the
> fly".
>
> Look at the following thread, for a proposal and discussion around this:
>
> https://groups.google.com/forum/#!searchin/ansible-project/override/ansible-project/9xRyYIOdSro/KustjP725kQJ
>
> If you find my proposal interesting, it would probably be more appropriate
> to make any comments at the other thread to keep relevant discussion at one
> place.
>
> --
> 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/536C782C.2050504%40yahoo.gr<https://groups.google.com/d/msgid/ansible-project/536C782C.2050504%40yahoo.gr?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/CA%2BnsWgy9cvC4tDSRJh7BRS%3DrN%2BQ__QLG_JKsWXkBghRRc0feEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to