diff --git a/defaults/main.yml b/defaults/main.yml index a168cbe2691b27ae44f7488e51efce30734879ca..b15c217be69054edecb605e9bd7c443b7edb0c93 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,15 +1,12 @@ -drupal_default_settings: [] drupal_install_drupal: true drupal_configure_drupal: true -drupal_update_drupal: true drupal_contrib_subdir: '' drupal_settings: - root: '{{ apache_server_default_root }}' version: 'd7' templates: [] drush_subkey: '' - create_drush_aliases: false - apache_site: false + create_drush_aliases: true src: mode: 'svn' url: '{{ apache_server_default_svn_target }}' @@ -18,9 +15,12 @@ drupal_settings: - domain: '{{ inventory_hostname }}.{{ internal_domain }}' aliases: [] shortname: '{{ inventory_hostname }}.{{ internal_domain }}' - dbname: '{{ inventory_hostname }}' - dbprefix: '' - dbhost: '{{ drupal_default_settings.dbhost }}' - protocol: 'http' + db: + name: '{{ inventory_hostname }}' + prefix: '' + host: '127.0.0.1' + extra: [] + protocol: 'https' multidomain: false extra_settings: [] + conf: [] diff --git a/tasks/apache.yml b/tasks/apache.yml index b94200d3a39c52414c460325f23f4bb0b2b52a4c..b21bd9a34fe6535fb5570fb1de5f1ca84924124f 100644 --- a/tasks/apache.yml +++ b/tasks/apache.yml @@ -1,20 +1,20 @@ --- # file: roles/drupal/tasks/apache.yml -- name: "Apache configuration file for our site(s)" +- name: "Apache Configuration File" template: src='vhost.conf' - dest='/etc/apache2/sites-available/{{ drupal.apache_site|default(drupal.jail.name) }}{{ apache_conf_ext }}' + dest='/etc/apache2/sites-available/{{ item.domain }}{{ apache_conf_ext }}' owner='root' group='root' mode='664' - when: drupal.jail is defined or drupal.apache_site + with_items: drupal.domains notify: - "Apache | Restart Apache" - name: "Apache enable our new site(s)" - command: a2ensite {{ drupal.apache_site|default(drupal.jail.name) }} creates=/etc/apache2/sites-enabled/{{ drupal.apache_site|default(drupal.jail.name) }}{{ apache_conf_ext }} - when: drupal.jail is defined or drupal.apache_site + command: a2ensite {{ item.domain }} creates=/etc/apache2/sites-enabled/{{ item.domain }}{{ apache_conf_ext }} + with_items: drupal.domains notify: - "Apache | Restart Apache" @@ -25,14 +25,16 @@ owner='www-data' group='www-data' mode=755 - when: drupal.apache_auth is defined + with_items: drupal.domains + when: item.apache_auth is defined - name: "Setup AuthType Basic" htpasswd: - path='{{ webRoot }}/passwords/{{ drupal.apache_auth.user }}' - name='{{ drupal.apache_auth.user }}' - password='{{ drupal.apache_auth.password }}' + path='{{ webRoot }}/passwords/{{ item.apache_auth.user }}' + name='{{ item.apache_auth.user }}' + password='{{ item.apache_auth.password }}' owner='www-data' group='www-data' mode='640' - when: drupal.apache_auth is defined + with_items: drupal.domains + when: item.apache_auth is defined diff --git a/tasks/configure.yml b/tasks/configure.yml index 08b02984d3823659d5d0bd905b6653eb268a6c49..b87f698802b671cca099d5645e0a3f535a3d4cf5 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -4,7 +4,7 @@ - name: "Configuration file" template: src='{{ item.src }}' - dest='{{ drupalRoot }}/{{ item.dest }}' + dest='{{ drupalRoot }}{{ item.dest }}' owner='www-data' group='www-data' mode='664' @@ -12,7 +12,7 @@ - name: "Create the sites sub-directories" file: - dest='{{ drupalRoot }}/sites/{{ item.0.shortname }}/{{ item.1 }}' + dest='{{ drupalRoot }}/sites/{{ item.0.shortname|default("default") }}/{{ item.1 }}' state='directory' owner='www-data' group='www-data' @@ -23,18 +23,18 @@ - name: "Create symbolic links" file: - src='{{ item.0.shortname }}' + src='{{ item.0.shortname|default("default") }}' path='{{ drupalRoot }}/sites/{{ item.1 }}' state=link with_subelements: - drupal.domains - aliases - when: drupal.version == 'd6' + when: drupal.version|default("d7") == "d6" - name: "Create the settings.php files" template: - src='{{ drupal.template_dir|default('') }}{{ drupal.version }}_settings.php' - dest='{{ drupalRoot }}/sites/{{ item.shortname }}/settings.php' + src='{{ drupal.template_dir|default('') }}{{ drupal.version|default("d7") }}_settings.php' + dest='{{ drupalRoot }}/sites/{{ item.shortname|default("default") }}/settings.php' owner='www-data' group='www-data' mode='444' diff --git a/tasks/install.gitscript.yml b/tasks/install.gitscript.yml index 837bef1cf7881430304c1750ede73d0415caffab..976a3b84d3cedf4bb586071da23d9979dad421c5 100644 --- a/tasks/install.gitscript.yml +++ b/tasks/install.gitscript.yml @@ -5,10 +5,10 @@ git: accept_hostkey: "yes" repo: "{{ drupal.src.git.repository }}" - dest: "{{ webRoot }}/{{ drupal.src.git.target }}" + dest: "{{ webRoot }}{{ drupal.src.git.target }}" force: "yes" version: "{{ drupal.src.git.branch|default(omit) }}" become: false - name: "Run Script" - shell: "{{ webRoot }}/{{ drupal.src.git.target }}/{{ drupal.src.script }}" + shell: "{{ webRoot }}{{ drupal.src.git.target }}{{ drupal.src.script }}" diff --git a/tasks/install.yml b/tasks/install.yml index 1ed999d9aaf770958998a1a518e2adb475f71049..0c847b98828802e6670986217585a7dcdf24683b 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -5,7 +5,7 @@ - set_fact: webRoot='/var/www' - set_fact: webRoot='{{ jailroot }}/{{ drupal.jail.name }}/var/www' when: drupal.jail is defined -- set_fact: drupalRoot='{{ webRoot }}/{{ drupal.root }}' +- set_fact: drupalRoot='{{ webRoot }}{{ drupal.root|default("") }}' - name: "Configure Apache" include: apache.yml @@ -31,7 +31,7 @@ register: drupal_available failed_when: false -- include: install.{{ drupal.src.mode }}.yml +- include: install.{{ drupal.src.mode|default("none") }}.yml when: drupal_install_drupal and drupal_available is defined and drupal_available.stdout != '{{ drupalRoot }}/index.php' - include: configure.yml when: drupal_configure_drupal @@ -46,7 +46,7 @@ - name: "Make site directories writeable" file: - path='{{ drupalRoot }}/sites/{{ item.0.shortname }}/{{ item.1 }}' + path='{{ drupalRoot }}/sites/{{ item.0.shortname|default("default") }}/{{ item.1 }}' mode='ug+w' recurse=yes with_nested: diff --git a/templates/d6_create_alias_links b/templates/d6_create_alias_links deleted file mode 100644 index 24cd3ff23b9681be68c1bba827a41d9d57d85def..0000000000000000000000000000000000000000 --- a/templates/d6_create_alias_links +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -cd {{ drupalRoot }}/sites - -{% for domain in drupal.domains %} -{% for alias in domain.aliases %} -ln -s {{ domain.shortname }} {{ alias }} -{% endfor %} -{% endfor %} diff --git a/templates/d6_settings.php b/templates/d6_settings.php index 2faa6be52ca00850ea571c4d4124e071ac32fb2e..92e2985f951b9394f66f3fa7ba3ee4465541bfd1 100644 --- a/templates/d6_settings.php +++ b/templates/d6_settings.php @@ -1,11 +1,11 @@ <?php -$db_url = 'mysql://root:{{ mysql_root_password }}@127.0.0.1/{{ item.dbname }}'; -$db_prefix = '{{ item.dbprefix }}'; +$db_url = 'mysql://root:{{ mysql_root_password }}@127.0.0.1/{{ item.db.name }}'; +$db_prefix = '{{ item.db.prefix|default("") }}'; $update_free_access = FALSE; -$base_url = '{{ item.protocol }}://{{ item.domain }}'; +$base_url = '{{ item.protocol|default("https") }}://{{ item.domain }}'; $cookie_domain = '{{ item.domain }}'; ini_set('arg_separator.output', '&'); @@ -22,6 +22,10 @@ ini_set('url_rewriter.tags', ''); $conf['clean_url'] = 1; -{% for line in item.extra_settings %} +{% for line in item.extra_settings|default([]) %} {{line}} {% endfor %} + +{% for config in item.conf|default([]) %} +$conf['{{ config.key }}'] = {{ config.value }}; +{% endfor %} diff --git a/templates/d7_settings.php b/templates/d7_settings.php index c666409ba16e5f00493400ee183ac6191e2ecae3..0575e02c6536c702633af60ba521235a10f1e2cc 100644 --- a/templates/d7_settings.php +++ b/templates/d7_settings.php @@ -3,33 +3,33 @@ $databases = array ( 'default' => array ( 'default' => array ( - 'driver' => 'mysql', - 'database' => '{{ item.dbname }}', + 'driver' => '{{ item.db.driver|default("mysql") }}', + 'database' => '{{ item.db.name }}', 'username' => 'root', 'password' => '{{ mysql_root_password }}', - 'host' => '127.0.0.1', - 'port' => '{{ hostvars[item.dbhost]['ssh_tunnel_ports'][0]['local'] }}', + 'host' => '{{ item.db.host|default("127.0.0.1") }}', + 'port' => '{{ hostvars[item.db.host|default(inventory_hostname)]['ssh_tunnel_ports'][0]['local'] }}', ), ), -{% for db in item.db_extra|default([]) %} +{% for db in item.db.extra|default([]) %} '{{ db.key }}' => array ( 'default' => array ( - 'driver' => 'mysql', - 'database' => '{{ db.dbname }}', + 'driver' => '{{ db.driver|default("mysql") }}', + 'database' => '{{ db.name }}', 'username' => 'root', 'password' => '{{ mysql_root_password }}', - 'host' => '127.0.0.1', - 'port' => '{{ hostvars[item.dbhost]['ssh_tunnel_ports'][0]['local'] }}', + 'host' => '{{ item.db.host|default("127.0.0.1") }}', + 'port' => '{{ hostvars[item.db.host|default(inventory_hostname)]['ssh_tunnel_ports'][0]['local'] }}', ), ), {% endfor %} ); -$db_prefix = '{{ item.dbprefix }}'; +$db_prefix = '{{ item.db.prefix|default("") }}'; $update_free_access = FALSE; -{% if not item.multidomain %} -$base_url = '{{ item.protocol }}://{{ item.domain }}'; +{% if not item.multidomain|default("FALSE") %} +$base_url = '{{ item.protocol|default("https") }}://{{ item.domain }}'; $cookie_domain = '{{ item.domain }}'; {% endif %} @@ -38,24 +38,25 @@ ini_set('session.gc_divisor', 100); ini_set('session.gc_maxlifetime', 200000); ini_set('session.cookie_lifetime', 2000000); -$conf['{{ item.protocol }}'] = TRUE; +$conf['{{ item.protocol|default("https") }}'] = TRUE; if (file_exists('sites/all/modules{{ drupal_contrib_subdir }}/redis/redis.autoload.inc')) { $conf['cache_backends'][] = 'sites/all/modules{{ drupal_contrib_subdir }}/redis/redis.autoload.inc'; $conf['cache_default_class'] = 'Redis_Cache'; - $conf['cache_prefix'] = '{{ item.shortname }}_'; + $conf['cache_prefix'] = '{{ item.shortname|default("default") }}_'; $conf['lock_inc'] = 'sites/all/modules{{ drupal_contrib_subdir }}/redis/redis.lock.inc'; $conf['path_inc'] = 'sites/all/modules{{ drupal_contrib_subdir }}/redis/redis.path.inc'; $conf['redis_client_interface'] = 'PhpRedis'; } -{% for line in item.extra_settings %} +{% for line in item.extra_settings|default([]) %} {{line}} {% endfor %} + {% for config in item.conf|default([]) %} $conf['{{ config.key }}'] = {{ config.value }}; {% endfor %} -{% if item.multidomain %} +{% if item.multidomain|default("FALSE") %} include DRUPAL_ROOT . '/sites/all/modules{{ drupal_contrib_subdir }}/domain/settings.inc'; {% endif %} diff --git a/templates/sites.php b/templates/sites.php index ac5f4a9844f83e775daa3195272e8299423cd432..7d471e8ca614f70c0a95b657a6fe268f9f6ec1d0 100644 --- a/templates/sites.php +++ b/templates/sites.php @@ -2,18 +2,16 @@ $sites = array( {% for drupaldomain in drupal.domains %} - '{{ drupaldomain.domain }}' => '{{ drupaldomain.shortname }}', -{% for alias in drupaldomain.aliases %} - '{{ alias }}' => '{{ drupaldomain.shortname }}', + '{{ drupaldomain.domain }}' => '{{ drupaldomain.shortname|default("default") }}', +{% for alias in drupaldomain.aliases|default([]) %} + '{{ alias }}' => '{{ drupaldomain.shortname|default("default") }}', {% endfor %} {% endfor %} -{% if drupal.sites_extra_domain is defined %} -{% for drupaldomain in drupal.sites_extra_domain %} - '{{ drupaldomain.domain }}' => '{{ drupaldomain.shortname }}', -{% for alias in drupaldomain.aliases %} - '{{ alias }}' => '{{ drupaldomain.shortname }}', +{% for drupaldomain in drupal.sites_extra_domain|default([]) %} + '{{ drupaldomain.domain }}' => '{{ drupaldomain.shortname|default("default") }}', +{% for alias in drupaldomain.aliases|default([]) %} + '{{ alias }}' => '{{ drupaldomain.shortname|default("default") }}', {% endfor %} {% endfor %} -{% endif %} //[NEXT] ); diff --git a/templates/vhost.conf b/templates/vhost.conf index e8abc35051e3d9e49ce7a43c57669a02daeb6532..5e5b1fcf70beb121632dfa06f0c99336306b6507 100644 --- a/templates/vhost.conf +++ b/templates/vhost.conf @@ -1,7 +1,7 @@ <VirtualHost *:80> ServerAdmin {{ apache_server_admin }} - ServerName {{ drupal.domains.0.domain }} - ServerAlias{% for domain in drupal.domains %} {{ domain.domain }}{% for alias in domain.aliases %} {{ alias }}{% endfor %}{% endfor %} + ServerName {{ item.domain }} + ServerAlias{% for alias in item.aliases|default([]) %} {{ alias }}{% endfor %} {% if drupal.jail is defined %} @@ -14,22 +14,18 @@ <Directory {{ drupalRoot }}/> Options Indexes FollowSymLinks MultiViews AllowOverride All -{% if drupal.apache_auth is defined %} - AuthType {{ drupal.apache_auth.type }} - AuthName "{{ drupal.apache_auth.name }}" - AuthUserFile {{ webRoot }}/passwords/{{ drupal.apache_auth.user }} - Require user {{ drupal.apache_auth.user }} +{% if item.apache_auth is defined %} + AuthType {{ item.apache_auth.type }} + AuthName "{{ item.apache_auth.name }}" + AuthUserFile {{ webRoot }}/passwords/{{ item.apache_auth.user }} + Require user {{ item.apache_auth.user }} {% else %} Order allow,deny allow from all {% endif %} </Directory> -{% if drupal.jail is defined %} - ErrorLog ${APACHE_LOG_DIR}/{{ drupal.jail.name }}-error.log -{% else %} - ErrorLog ${APACHE_LOG_DIR}/error.log -{% endif %} + ErrorLog ${APACHE_LOG_DIR}/{{ item.domain }}-error.log LogLevel warn LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded