Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple dependencies #66

Closed
nschloe opened this issue Sep 9, 2015 · 11 comments
Closed

Allow multiple dependencies #66

nschloe opened this issue Sep 9, 2015 · 11 comments

Comments

@nschloe
Copy link

nschloe commented Sep 9, 2015

I would like to use ansible-role-nginx to add several nginx configurations from different roles to /etc/nginx/sites-{available,enabled}/. Unfortunately, the module doesn't support this yet. The Ansible docs say

By default, roles can also only be added as a dependency once - if another role also lists it as a dependency it will not be run again. This behavior can be overridden by adding allow_duplicates: yes to the meta/main.yml file.

Any thoughts on that?

@jdauphant
Copy link
Owner

Hi @nschloe ,

You can use multiple time the role in a playbook.
For example :

- role: nginx // for the packages installation
  nginx_sites: [] // you can declare your default pages
- phpmyadmin
- role: nginx
  nginx_installation_type: "configuration-only" // this line is not mandatory, it's a optimisation
  nginx_sites:
     phpmyadmin: "{{phpmyadmin_nginx_config}}"

Sites name and config name need to have different name between several usage.
Best regards,
Julien

@andrenarchy
Copy link

We have two roles webserver and jenkins and both should add a vhost configuration for nginx. In a role's tasks/main.yml, your proposed code doesn't work. Any idea how to get this running? Thx!

@jdauphant
Copy link
Owner

@andrenarchy can you give more details on what doesn't work ?

@andrenarchy
Copy link

I don't see how a role (nginx) can be called from the tasks/main.yml of another role.

I guess we can only call a role from another role with dependencies in meta/main.yml. In our case, the roles webserver and jenkins depend on nginx:

# roles/webserver/meta/main.yml
dependencies:
  - role: jdauphant.nginx
    nginx_installation_type: "configuration-only"
    # global nginx params
    nginx_http_params:
      - sendfile "on"
      # ...
    nginx_sites:
      main_https:
        # listen ...
# roles/jenkins/meta/main.yml
dependencies:
  - role: jdauphant.nginx
    nginx_installation_type: "configuration-only"
    nginx_sites:
      jenkins_https:
        # listen ...

If jenkins is called after webserver, it overwrites the nginx.conf with the default config provided in https://github.com/jdauphant/ansible-role-nginx/blob/master/defaults/main.yml#L36. It would be nice to put the nginx role into a mode where only the provided keys are processed. Is this possible?

@jdauphant
Copy link
Owner

@andrenarchy I see. You can use nginx_config variable :

dependencies:
  - role: jdauphant.nginx
    nginx_installation_type: "configuration-only"
    # global nginx params
    nginx_http_params: {}
    nginx_configs:
      webserver:
        - sendfile "on"
      # ...
    nginx_sites:
      main_https:
        # listen ...

(Maybe, we should deprecated nginx_http_params and use nginx_config with a default config)

@nschloe @andrenarchy I have add "allow_duplicates: yes" in the last version 1.7.1

Best regards,
Julien

@andrenarchy
Copy link

So your idea is to trim nginx.conf to the include statements, right? Sounds like a good plan! But then: why differentiate between conf.d and site includes at all? Don't they all end up in the http block?

Thx for adding allow_duplicates! :-)

@jdauphant
Copy link
Owner

nginx_sites are directly included in "server {}" block, nginx_config are not.
nginx_sites are specific configuration, nginx_config are generic configuration.
This force to separate things in logical and more maintainable way.

@andrenarchy
Copy link

@jdauphant Your proposed config works like a charm (after I realized that nginx_config should be nginx_configs). Thanks!

In order to reduce the overhead for multiple calls to the module, I overwrite the defaults in group_vars/all with:

nginx_installation_type: "configuration-only"
nginx_http_params: {}
nginx_configs: {}
nginx_sites: {}

Maybe this is of interest for others.

Anyway, I think this issue can be closed. :)

@jdauphant
Copy link
Owner

Ah, sorry for the mistake in the name. I have corrected that.

@jdauphant
Copy link
Owner

@nschloe I have close the issue, if we have some problem don't hesitate to comments.

@nschloe
Copy link
Author

nschloe commented Sep 15, 2015

Everything working as expected! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants