diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 146d41c..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/molecule/default/tests/__pycache__/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..53f4980 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Oliver Davies + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 555d701..9348d55 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,32 @@ -Role Name -========= +# Ansible Role: Drupal settings -A brief description of the role goes here. +A role for automatically generating `settings.php` files for Drupal 7 and 8 applications. -Requirements ------------- +## Example -Any pre-requisites that may not be covered by Ansible itself or the role should -be mentioned here. For instance, if the role uses the EC2 module, it may be a -good idea to mention in this section that the boto package is required. - -Role Variables --------------- - -A description of the settable variables for this role should go here, including -any variables that are in defaults/main.yml, vars/main.yml, and any variables -that can/should be set via parameters to the role. Any variables that are read -from other roles and/or the global scope (ie. hostvars, group vars, etc.) should -be mentioned here as well. - -Dependencies ------------- - -A list of other roles hosted on Galaxy should go here, plus any details in -regards to parameters that may need to be set for other roles, or variables that -are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables -passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: opdavies.drupal-settings, x: 42 } - -License -------- - -BSD - -Author Information ------------------- - -An optional section for the role authors to include contact information, or a -website (HTML is not allowed). +```yaml +drupal_settings: + - drupal_root: /var/www/web + sites: + - name: default + filename: settings.php # Optional, defaults to 'settings.php' + settings: + base_url: https://www.example.com # Optional, Drupal 7 + hash_salt: '' # Optional + databases: + default: # The database key + default: # The database target + driver: mysql # Optional, defaults to 'mysql' + host: localhost # Optional, defaults to 'localhost' + port: 3306 # Optional + database: mydatabase + username: user + password: secret + config_directories: # Optional, Drupal 8 + sync: path/to/config + trusted_hosts: # Optional, Drupal 8 + - '^example\.com$' + - '^.+\.example\.com$' + - '^example\.org$' + - '^.+\.example\.org$' +``` diff --git a/handlers/main.yml b/handlers/main.yml deleted file mode 100644 index 90858c5..0000000 --- a/handlers/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# handlers file for opdavies.drupal-settings diff --git a/meta/main.yml b/meta/main.yml index a4c0a1d..08a4bc2 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,21 +1,16 @@ --- galaxy_info: - author: Oliver Davies - description: Automatically generate Drupal settings files. + role_name: drupal-settings-files + author: opdavies + description: Automatically generates settings files for Drupal applications license: MIT - min_ansible_version: 1.2 platforms: - - name: GenericUNIX - versions: - - all - - any - - name: GenericBSD - versions: - - all - - any - - name: GenericLinux - versions: - - all - - any - galaxy_tags: - - drupal + - name: EL + versions: [all] + - name: Debian + versions: [all] + - name: Ubuntu + versions: [all] + galaxy_tags: [drupal, php, cms, web, development] + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml index fbc23b4..71ebba5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,16 +1,18 @@ --- -- name: Ensure that Drupal site directories are present +- name: Ensure directory exists file: state: directory - path: '{{ item.0.root }}/sites/{{ item.1.name|default("default") }}' + path: '{{ item.0.drupal_root }}/sites/{{ item.1.name|default("default") }}' with_subelements: - '{{ drupal_settings }}' - sites + no_log: true -- name: Ensure that Drupal settings files are present +- name: Create settings files template: src: settings.php.j2 - dest: '{{ item.0.root }}/sites/{{ item.1.name|default("default") }}/{{ item.1.filename|default("settings.php") }}' + dest: '{{ item.0.drupal_root }}/sites/{{ item.1.name|default("default") }}/{{ item.1.filename|default("settings.php") }}' with_subelements: - '{{ drupal_settings }}' - sites + no_log: true diff --git a/templates/settings.php.j2 b/templates/settings.php.j2 index e69de29..bd7ad99 100644 --- a/templates/settings.php.j2 +++ b/templates/settings.php.j2 @@ -0,0 +1,43 @@ + '{{ values.driver|default('mysql') }}', + 'host' => '{{ values.host|default('localhost') }}', + 'port' => '{{ values.port|default('3306') }}', + 'database' => '{{ values.database }}', + 'username' => '{{ values.username }}', + 'password' => '{{ values.password }}', +); + +{% endfor %} +{% endfor %} + +{% if item.1.settings.base_url is defined %} +$base_url = '{{ item.1.settings.base_url }}'; +{% endif %} + +{% if item.1.settings.hash_salt is defined %} +$settings['hash_salt'] = '{{ item.1.settings.hash_salt }}'; +{% endif %} + +{% if item.1.settings.config_directories is defined %} +{% for name, value in item.1.settings.config_directories.items() %} +$config_directories['{{ name }}'] = '{{ value }}'; +{% endfor %} +{% endif %} + +{% if item.1.settings.trusted_hosts is defined %} +$settings['trusted_host_patterns'] = array( +{% for host in item.1.settings.trusted_hosts %} + '{{ host }}', +{% endfor %} +); +{% endif %} + +{% if item.1.settings.extra_parameters is defined %} + {{ item.1.settings.extra_parameters|indent(0) }} +{% endif %} diff --git a/vars/main.yml b/vars/main.yml deleted file mode 100644 index 19e6394..0000000 --- a/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for opdavies.drupal-settings