diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..146d41c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/molecule/default/tests/__pycache__/ diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 53f4980..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -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 9348d55..555d701 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,48 @@ -# Ansible Role: Drupal settings +Role Name +========= -A role for automatically generating `settings.php` files for Drupal 7 and 8 applications. +A brief description of the role goes here. -## Example +Requirements +------------ -```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$' -``` +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). diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..90858c5 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for opdavies.drupal-settings diff --git a/meta/main.yml b/meta/main.yml index 08a4bc2..a4c0a1d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,16 +1,21 @@ --- galaxy_info: - role_name: drupal-settings-files - author: opdavies - description: Automatically generates settings files for Drupal applications + author: Oliver Davies + description: Automatically generate Drupal settings files. license: MIT + min_ansible_version: 1.2 platforms: - - name: EL - versions: [all] - - name: Debian - versions: [all] - - name: Ubuntu - versions: [all] - galaxy_tags: [drupal, php, cms, web, development] - -dependencies: [] + - name: GenericUNIX + versions: + - all + - any + - name: GenericBSD + versions: + - all + - any + - name: GenericLinux + versions: + - all + - any + galaxy_tags: + - drupal diff --git a/tasks/main.yml b/tasks/main.yml index 71ebba5..fbc23b4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,18 +1,16 @@ --- -- name: Ensure directory exists +- name: Ensure that Drupal site directories are present file: state: directory - path: '{{ item.0.drupal_root }}/sites/{{ item.1.name|default("default") }}' + path: '{{ item.0.root }}/sites/{{ item.1.name|default("default") }}' with_subelements: - '{{ drupal_settings }}' - sites - no_log: true -- name: Create settings files +- name: Ensure that Drupal settings files are present template: src: settings.php.j2 - dest: '{{ item.0.drupal_root }}/sites/{{ item.1.name|default("default") }}/{{ item.1.filename|default("settings.php") }}' + dest: '{{ item.0.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 bd7ad99..e69de29 100644 --- a/templates/settings.php.j2 +++ b/templates/settings.php.j2 @@ -1,43 +0,0 @@ - '{{ 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 new file mode 100644 index 0000000..19e6394 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for opdavies.drupal-settings