瀏覽代碼

Add support for PHPPgAdmin

Emmanuel Bouthenot 9 年之前
父節點
當前提交
16cc12ec86

+ 3 - 3
roles/webserver/defaults/main.yml

@@ -46,8 +46,8 @@ phpmyadmin_vhostname: pma.localhost
 http_auth_phpmyadmin_username: ''
 http_auth_phpmyadmin_password: ''
 
-http_auth_user_name: ''
-http_auth_user_password: ''
-http_auth_admin_password: seVDetGvSs7nA # openssl passwd -crypt adm123in
+with_phppgadmin: False
+phppgadmin_vhostname: 'pga.localhost'
+http_auth_phppgadmin: False
 
 # vim: ft=yaml

+ 12 - 0
roles/webserver/tasks/apache2.yml

@@ -30,6 +30,18 @@
     - Reload apache2
   when: with_phpmyadmin and with_apache2
 
+- name: Install PHPPgAdmin virtual host for apache2 (sites-available)
+  template: src=apache2/pga_vhost.j2 dest=/etc/apache2/sites-available/pga.conf owner=root group=root mode=0644
+  notify:
+    - Reload apache2
+  when: with_phppgadmin and with_apache2
+
+- name: Install PHPPgAdmin virtual host for apache2 (sites-enabled)
+  file: src=/etc/apache2/sites-available/pga.conf path=/etc/apache2/sites-enabled/pga.conf state=link
+  notify:
+    - Reload apache2
+  when: with_phppgadmin and with_apache2
+
 - name: Install PHP system checks virtual host for apache2 (sites-available)
   template: src=apache2/sys_vhost.j2 dest=/etc/apache2/sites-available/sys.conf owner=root group=root mode=0644
   notify:

+ 12 - 0
roles/webserver/tasks/nginx.yml

@@ -49,6 +49,18 @@
     - Reload nginx
   when: with_phpmyadmin and with_nginx
 
+- name: Install PHPPgAdmin virtual host for nginx (sites-available)
+  template: src=nginx/pga_vhost.j2 dest=/etc/nginx/sites-available/pga owner=root group=root mode=0644
+  notify:
+    - Reload nginx
+  when: with_phppgadmin and with_nginx
+
+- name: Install PHPPgAdmin virtual host for nginx (sites-enabled)
+  file: src=/etc/nginx/sites-available/pga path=/etc/nginx/sites-enabled/pga state=link
+  notify:
+    - Reload nginx
+  when: with_phppgadmin and with_nginx
+
 - name: Install PHP system checks virtual host for nginx (sites-available)
   template: src=nginx/sys_vhost.j2 dest=/etc/nginx/sites-available/sys owner=root group=root mode=0644
   notify:

+ 4 - 0
roles/webserver/tasks/php.yml

@@ -66,6 +66,10 @@
   apt: pkg=phpmyadmin state=installed update_cache=yes
   when: with_phpmyadmin
 
+- name: Install PHPPgAdmin
+  apt: pkg=phppgadmin state=installed update_cache=yes
+  when: with_phppgadmin
+
 - name: Install php5-fpm package
   apt: pkg=php5-fpm state=installed update_cache=yes
   when: with_fpm

+ 30 - 0
roles/webserver/templates/apache2/pga_vhost.j2

@@ -0,0 +1,30 @@
+{% if ansible_prolog -%}
+{% from 'templates/ansible/prolog.j2' import prolog with context %}
+{{ prolog() }}
+{% endif -%}
+# Apache vhost for phppgadmin
+
+<VirtualHost *:80>
+    ServerName {{ phppgadmin_vhostname }}
+
+    DocumentRoot /usr/share/phppgadmin
+    DirectoryIndex index.php
+
+{% if http_auth_phppgadmin %}
+    <Location />
+        AuthType basic
+        AuthName "Restricted Access"
+        AuthUserFile /etc/apache2/auth_admin
+        Require valid-user
+    </Location>
+{% endif %}
+
+    <Directory /usr/share/phppgadmin>
+        Require all granted
+    </Directory>
+
+    LogLevel warn
+    CustomLog ${APACHE_LOG_DIR}/pga.access.log combined
+    ErrorLog ${APACHE_LOG_DIR}/pga.error.log
+
+</VirtualHost>

+ 27 - 0
roles/webserver/templates/nginx/pga_vhost.j2

@@ -0,0 +1,27 @@
+{% if ansible_prolog -%}
+{% from 'templates/ansible/prolog.j2' import prolog with context %}
+{{ prolog() }}
+{% endif -%}
+# Nginx vhost for phppgadmin
+
+server {
+    server_name {{ phppgadmin_vhostname }};
+
+    access_log  /var/log/nginx/pma.access.log;
+    error_log   /var/log/nginx/pma.error.log;
+
+    root /usr/share/phppgadmin;
+    index index.php;
+    try_files $uri $uri/ /index.php;
+
+{% if http_auth_phppgadmin %}
+    auth_basic "Restricted Access";
+    auth_basic_user_file /etc/nginx/auth_admin;
+{% endif %}
+
+    client_max_body_size 32m;
+
+    location ~ \.php(/|$) {
+        include fastcgi_pass_fpm;
+    }
+}