-
Notifications
You must be signed in to change notification settings - Fork 303
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
[TASK] Add support for generic configuration snippets #33
Conversation
Hi @Tuurlijk , Why use snippets and not use the powerful template system of Ansible ? Thanks in advance for you answer |
To avoid code duplication in nginx configuration. here is an example configuration: nginx_snippets:
php-fpm:
- add_header X-TYPO3-Homestead-backend php-fpm
- try_files $uri $uri/ /index.php?$args
- location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
php-fpm-xhprof:
- add_header X-TYPO3-Homestead-backend php-fpm-xhprof
- try_files $uri $uri/ /index.php?$args
- location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm-xhprof.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
hhvm:
- add_header X-TYPO3-Homestead-backend hhvm
- try_files $uri $uri/ /index.php?$args
- location ~ \.(hh|php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/hhvm/sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginx_sites:
default:
- listen 80 default_server
- server_name _
- root "{{ typo3_source_path }}/homestead/"
- include snippets/hhvm.conf
default-ssl:
- listen 443 default_server
- server_name _
- root "{{ typo3_source_path }}/homestead/"
- include snippets/php-fpm.conf
- ssl on
- ssl_certificate {{nginx_conf_dir}}/ssl/typo3.homestead.crt
- ssl_certificate_key {{nginx_conf_dir}}/ssl/typo3.homestead.key How would you do this with ansible templates? |
It could be implemented like that :
The result is :
This work with the actual role but made ugly config file. I have made a patch that made good visual config file with this configuration : What do you think about that ? |
Wow, ansible is powerful. I like it. It will do the job. But this will require a re-provision if I want to modify 'nginx_hhvm' and see the change reflected in all sites. Currently this is not so nice to do since the tags attached to the actions are too generic (configuration,nginx) and can not be 'AND'-ed when calling ansible provision (as far as I know). Can you please add an explicit tag to either all the actions in configuration.yml, OR to the configuration.yml include statement?
I would prefer the last option. |
The tags selection is not so good with ansible but I prefer not introduce too much tags. |
My role is also made that you can use it multiple time on the same server. |
I know you can add and remove tags. But the 'nginx' tag is used in more tasks than just the configuration task. It will also trigger the remove-* tasks and go over the installation task again. So I still think it makes sense to be able to trigger just the 'site configuration' alone. |
[TASK] Split nginx configuration into nginx and sites
Hello @Tuurlijk , For the tags issue : I will think about integrate some undocumented tags like nginx-configuration, nginx-packages, nginx-service (In an ideal world, I would prefer this integrated directly in ansible-playbook) |
Tested your solution, works as expected. Things I dislike about it are:
|
|
No, code duplication is not a real problem in this case. It's just in my mind. Can you please merge in your solution? Thx for the tip on being able to mix the notations. but I agree mixing them does not make it more readable. |
It's already merged and I just release it at 1.2 : https://github.com/jdauphant/ansible-role-nginx/releases/tag/v1.2 Thanks for your help @Tuurlijk |
This patch adds support for generic reusable configuration snippets like php request handling through a php-fpm socket or hhvm.