From 1ce24da658bf20224fb1a9b82e57f7682b60a3fd Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Sun, 25 Mar 2018 15:55:51 +0200 Subject: [PATCH] ansible-playbooks/general#72 Always use import_tasks or include_tasks instead of just include --- tasks/apache.yml | 60 ++++------ tasks/apache_auth.yml | 19 +++ tasks/collect_config/collect.yml | 35 ++++++ tasks/collect_config/commit/gitflow.yml | 3 +- tasks/collect_config/main.yml | 48 ++------ tasks/deploy/gitcomposer.yml | 50 ++++---- tasks/deploy/gitscript.yml | 58 ++++----- tasks/deploy/post-tasks.yml | 44 +++---- tasks/files.yml | 79 +++++-------- tasks/files_mount.yml | 20 ++++ tasks/install.yml | 12 +- tasks/main.yml | 12 +- tasks/mysql.yml | 150 ++++++++++++------------ tasks/scss.yml | 36 +++--- tasks/users/gitcomposer.yml | 40 ++++--- tasks/users/gitscript.yml | 62 ++++------ tasks/users/gitscript_cron.yml | 22 ++++ 17 files changed, 399 insertions(+), 351 deletions(-) create mode 100644 tasks/apache_auth.yml create mode 100644 tasks/collect_config/collect.yml create mode 100644 tasks/files_mount.yml create mode 100644 tasks/users/gitscript_cron.yml diff --git a/tasks/apache.yml b/tasks/apache.yml index dd9bb8a..c1e47ff 100644 --- a/tasks/apache.yml +++ b/tasks/apache.yml @@ -1,45 +1,31 @@ --- # file: roles/drupal/tasks/apache.yml -- name: "Apache Configuration File" - template: - src='vhost.conf' - dest='/etc/apache2/sites-available/{{ drupal.id }}-{{ drupal_domain.shortname|default("default") }}{{ apache_conf_ext }}' - owner='root' - group='root' - mode='664' - notify: - - "Apache | Restart Apache" - -- name: "Apache enable our new site(s)" - command: a2ensite {{ drupal.id }}-{{ drupal_domain.shortname|default("default") }} creates=/etc/apache2/sites-enabled/{{ drupal.id }}-{{ drupal_domain.shortname|default("default") }}{{ apache_conf_ext }} - notify: - - "Apache | Restart Apache" +- block: -- name: "Apache install SSL certificates" - copy: - src='{{inventory_dir}}/files/ssl/{{ item.file }}' - dest='/etc/ssl/private' - with_items: '{{ drupal_domain.certs|default([]) }}' - notify: "Apache | Restart Apache" + - name: "Apache Configuration File" + template: + src='vhost.conf' + dest='/etc/apache2/sites-available/{{ drupal.id }}-{{ drupal_domain.shortname|default("default") }}{{ apache_conf_ext }}' + owner='root' + group='root' + mode='664' + notify: + - "Apache | Restart Apache" -- block: + - name: "Apache enable our new site(s)" + command: a2ensite {{ drupal.id }}-{{ drupal_domain.shortname|default("default") }} creates=/etc/apache2/sites-enabled/{{ drupal.id }}-{{ drupal_domain.shortname|default("default") }}{{ apache_conf_ext }} + notify: + - "Apache | Restart Apache" - - name: "Ensure Password Directory" - file: - path='{{ webRoot }}/passwords' - state='directory' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='755' + - name: "Apache install SSL certificates" + copy: + src='{{inventory_dir}}/files/ssl/{{ item.file }}' + dest='/etc/ssl/private' + with_items: '{{ drupal_domain.certs|default([]) }}' + notify: "Apache | Restart Apache" - - name: "Setup AuthType Basic" - htpasswd: - path='{{ webRoot }}/passwords/{{ drupal_domain.apache_auth.user }}' - name='{{ drupal_domain.apache_auth.user }}' - password='{{ drupal_domain.apache_auth.password }}' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='640' + - import_tasks: apache_auth.yml + when: drupal_domain.apache_auth is defined - when: drupal_domain.apache_auth is defined + tags: 'ApacheConfig' diff --git a/tasks/apache_auth.yml b/tasks/apache_auth.yml new file mode 100644 index 0000000..747e383 --- /dev/null +++ b/tasks/apache_auth.yml @@ -0,0 +1,19 @@ +--- +# file: roles/drupal/tasks/apache_auth.yml + +- name: "Ensure Password Directory" + file: + path='{{ webRoot }}/passwords' + state='directory' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='755' + +- name: "Setup AuthType Basic" + htpasswd: + path='{{ webRoot }}/passwords/{{ drupal_domain.apache_auth.user }}' + name='{{ drupal_domain.apache_auth.user }}' + password='{{ drupal_domain.apache_auth.password }}' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='640' diff --git a/tasks/collect_config/collect.yml b/tasks/collect_config/collect.yml new file mode 100644 index 0000000..264e60d --- /dev/null +++ b/tasks/collect_config/collect.yml @@ -0,0 +1,35 @@ +--- +# file: roles/drupal/tasks/collect_config/main.yml + +- import_tasks: 'prepare/{{ collectConfig.mode|default("none") }}.yml' + +- name: "Move exported config to working copy" + command: 'mv {{ pathExport }} {{ pathWorking }}' + # Note: If parallel processes are running the pathExport could be gone by now. + failed_when: false + ignore_errors: true + +- name: "Ensure working directory" + file: + path: '{{ pathWorking }}' + state: 'directory' + +- name: "Read file name in working copy" + shell: 'ls {{ pathWorking }} -1' + register: list_config_files + +- name: "Copy working copy to config path" + copy: + src: '{{ pathWorking }}/{{ item }}' + dest: '{{ pathConfig }}/{{ item }}' + remote_src: yes + with_items: '{{ list_config_files.stdout_lines }}' + +- import_tasks: 'commit/{{ collectConfig.mode|default("none") }}.yml' + +- import_tasks: 'finish/{{ collectConfig.mode|default("none") }}.yml' + +- name: "Delete working copy" + file: + path: '{{ pathWorking }}' + state: absent diff --git a/tasks/collect_config/commit/gitflow.yml b/tasks/collect_config/commit/gitflow.yml index 0d2e9f1..5e4a66f 100644 --- a/tasks/collect_config/commit/gitflow.yml +++ b/tasks/collect_config/commit/gitflow.yml @@ -1,5 +1,4 @@ --- # file: roles/drupal/tasks/config_collect/commit/gitflow.yml -- include_tasks: 'git.yml' - tags: 'always' +- import_tasks: 'git.yml' diff --git a/tasks/collect_config/main.yml b/tasks/collect_config/main.yml index c58fc08..f45b8ad 100644 --- a/tasks/collect_config/main.yml +++ b/tasks/collect_config/main.yml @@ -2,6 +2,7 @@ # file: roles/drupal/tasks/collect_config/main.yml - block: + - set_fact: version='{{ lookup('pipe','date +%Y-%m-%d-%H-%M-%S') }}' - set_fact: @@ -11,46 +12,13 @@ pathExport='{{ export_path }}' pathWorking='/tmp/ansible-cae-{{ drupal.jail.name }}-{{ version }}' collectConfig={{ drupal.src.collectConfig|default([]) }} - tags: 'always' - -- name: "Check if export path exists" - stat: - path: "{{ pathExport }}" - register: path_export_stat - -- block: - - - include: 'prepare/{{ collectConfig.mode|default("none") }}.yml' - - - name: "Move exported config to working copy" - command: 'mv {{ pathExport }} {{ pathWorking }}' - # Note: If parallel processes are running the pathExport could be gone by now. - failed_when: false - ignore_errors: true - - - name: "Ensure working directory" - file: - path: '{{ pathWorking }}' - state: 'directory' - - - name: "Read file name in working copy" - shell: 'ls {{ pathWorking }} -1' - register: list_config_files - - - name: "Copy working copy to config path" - copy: - src: '{{ pathWorking }}/{{ item }}' - dest: '{{ pathConfig }}/{{ item }}' - remote_src: yes - with_items: '{{ list_config_files.stdout_lines }}' - - - include: 'commit/{{ collectConfig.mode|default("none") }}.yml' - - include: 'finish/{{ collectConfig.mode|default("none") }}.yml' + - name: "Check if export path exists" + stat: + path: "{{ pathExport }}" + register: path_export_stat - - name: "Delete working copy" - file: - path: '{{ pathWorking }}' - state: absent + - import_tasks: collect.yml + when: path_export_stat.stat.exists - when: path_export_stat.stat.exists + tags: 'deploy' diff --git a/tasks/deploy/gitcomposer.yml b/tasks/deploy/gitcomposer.yml index 862158c..e6db796 100644 --- a/tasks/deploy/gitcomposer.yml +++ b/tasks/deploy/gitcomposer.yml @@ -1,28 +1,32 @@ --- # file: roles/drupal/tasks/deploy/gitcomposer.yml -- name: "Ensure Repository Directory" - file: - path: '{{ webRoot }}' - state: 'directory' - owner: 'root' - group: 'root' - mode: 'u+rwX,g+rwX,o+rX' - recurse: yes +- block: -- name: "Clone Git Repository" - git: - accept_hostkey: yes - repo: '{{ drupal.src.git.repository }}' - dest: '{{ webRoot }}' - force: yes - version: '{{ drupal.src.git.branch|default(omit) }}' - become: false + - name: "Ensure Repository Directory" + file: + path: '{{ webRoot }}' + state: 'directory' + owner: 'root' + group: 'root' + mode: 'u+rwX,g+rwX,o+rX' + recurse: yes -- name: "Run Composer" - composer: - command='install' - working_dir='{{ webRoot }}' - no_dev=yes - optimize_autoloader=yes - prefer_dist=yes + - name: "Clone Git Repository" + git: + accept_hostkey: yes + repo: '{{ drupal.src.git.repository }}' + dest: '{{ webRoot }}' + force: yes + version: '{{ drupal.src.git.branch|default(omit) }}' + become: false + + - name: "Run Composer" + composer: + command='install' + working_dir='{{ webRoot }}' + no_dev=yes + optimize_autoloader=yes + prefer_dist=yes + + tags: 'deploy' diff --git a/tasks/deploy/gitscript.yml b/tasks/deploy/gitscript.yml index 1bd49b0..f588c3f 100644 --- a/tasks/deploy/gitscript.yml +++ b/tasks/deploy/gitscript.yml @@ -1,33 +1,37 @@ --- # file: roles/drupal/tasks/deploy/gitscript.yml -- name: "Ensure Repository Directory" - file: - path: '{{ webRoot }}{{ drupal.src.git.target }}' - state: 'directory' - owner: 'root' - group: 'root' - mode: '775' +- block: -- name: "Clone Git Repository" - git: - accept_hostkey: yes - bare: '{{ drupal.src.git.bare|default(omit) }}' - repo: '{{ drupal.src.git.repository }}' - dest: '{{ webRoot }}{{ drupal.src.git.target }}' - force: yes - version: '{{ drupal.src.git.branch|default(omit) }}' - become: false - when: drupal_first_installation or not drupal.src.git.bare|default(false) + - name: "Ensure Repository Directory" + file: + path: '{{ webRoot }}{{ drupal.src.git.target }}' + state: 'directory' + owner: 'root' + group: 'root' + mode: '775' -- name: "Second Clone Git Repository" - git: - repo: '{{ webRoot }}{{ drupal.src.git.target }}' - dest: '{{ webRoot }}{{ drupal.src.git.target2 }}' - force: yes - version: '{{ drupal.src.git.branch|default(omit) }}' - when: drupal.src.git.target2 is defined and (drupal_first_installation or not drupal.src.git.bare|default(false)) + - name: "Clone Git Repository" + git: + accept_hostkey: yes + bare: '{{ drupal.src.git.bare|default(omit) }}' + repo: '{{ drupal.src.git.repository }}' + dest: '{{ webRoot }}{{ drupal.src.git.target }}' + force: yes + version: '{{ drupal.src.git.branch|default(omit) }}' + become: false + when: drupal_first_installation or not drupal.src.git.bare|default(false) -- name: "Run Script" - shell: '{{ webRoot }}{{ drupal.src.git.target }}{{ drupal.src.script }}' - when: drupal.src.script is defined and drupal.src.script + - name: "Second Clone Git Repository" + git: + repo: '{{ webRoot }}{{ drupal.src.git.target }}' + dest: '{{ webRoot }}{{ drupal.src.git.target2 }}' + force: yes + version: '{{ drupal.src.git.branch|default(omit) }}' + when: drupal.src.git.target2 is defined and (drupal_first_installation or not drupal.src.git.bare|default(false)) + + - name: "Run Script" + shell: '{{ webRoot }}{{ drupal.src.git.target }}{{ drupal.src.script }}' + when: drupal.src.script is defined and drupal.src.script + + tags: 'deploy' diff --git a/tasks/deploy/post-tasks.yml b/tasks/deploy/post-tasks.yml index 1f1c1ca..6b101f0 100644 --- a/tasks/deploy/post-tasks.yml +++ b/tasks/deploy/post-tasks.yml @@ -1,25 +1,29 @@ --- # file: roles/drupal/tasks/deploy/post-tasks.yml -- set_fact: - drushAlias='@{{ drupal.id }}.{{ drupal_domain.shortname|default("default") }}' - drushAliasValidate="'@{{ drupal.id }}.{{ drupal_domain.shortname|default('default') }}':" -- set_fact: - drushAlias='@{{ inventory_hostname }}{{ drushSubkey }}.{{ drupal_domain.shortname|default("default") }}' - drushAliasValidate='@{{ inventory_hostname }}{{ drushSubkey }}.{{ drupal_domain.shortname|default("default") }}' - when: drush_version_main|default('8') == '8' +- block: -- name: "Check Drush Status" - shell: drush -y {{ drushAlias }} status - args: - chdir: '{{ webRoot }}' - register: drush_status - changed_when: false - when: drushAliasValidate in drush_aliases.stdout_lines + - set_fact: + drushAlias='@{{ drupal.id }}.{{ drupal_domain.shortname|default("default") }}' + drushAliasValidate="'@{{ drupal.id }}.{{ drupal_domain.shortname|default('default') }}':" + - set_fact: + drushAlias='@{{ inventory_hostname }}{{ drushSubkey }}.{{ drupal_domain.shortname|default("default") }}' + drushAliasValidate='@{{ inventory_hostname }}{{ drushSubkey }}.{{ drupal_domain.shortname|default("default") }}' + when: drush_version_main|default('8') == '8' -- name: "Run Post Deploy Tasks" - shell: drush -y {{ drushAlias }} {{ item }} - args: - chdir: '{{ webRoot }}' - with_items: '{{ drupal_post_deploy_tasks[drupal.version|default("d7")] }}' - when: "drush_status is defined and ('Successful' in drush_status.stdout|default('') or 'Erfolgreich' in drush_status.stdout|default(''))" + - name: "Check Drush Status" + shell: drush -y {{ drushAlias }} status + args: + chdir: '{{ webRoot }}' + register: drush_status + changed_when: false + when: drushAliasValidate in drush_aliases.stdout_lines + + - name: "Run Post Deploy Tasks" + shell: drush -y {{ drushAlias }} {{ item }} + args: + chdir: '{{ webRoot }}' + with_items: '{{ drupal_post_deploy_tasks[drupal.version|default("d7")] }}' + when: "drush_status is defined and ('Successful' in drush_status.stdout|default('') or 'Erfolgreich' in drush_status.stdout|default(''))" + + tags: 'deploy' diff --git a/tasks/files.yml b/tasks/files.yml index 33f9da2..196435b 100644 --- a/tasks/files.yml +++ b/tasks/files.yml @@ -1,63 +1,48 @@ --- # file: roles/drupal/tasks/files.yml -- set_fact: - dir='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' - src='{{ relativeRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' - dest='{{ drupalRoot }}/sites/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' - - block: - - name: "Ensure mounted directory" + - set_fact: + dir='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' + src='{{ relativeRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' + dest='{{ drupalRoot }}/sites/{{ drupal_domain.0.shortname|default("default") }}/{{ drupal_domain.1 }}' + + - import_tasks: files_mount.yml + when: drupal_domain.0.mountpoint is defined + + - name: "Ensure File Directories" file: - path='{{ drupal_domain.0.mountpoint }}/{{ drupal.id }}/{{ drupal_domain.0.shortname|default("default") }}' + dest='{{ dir }}' state='directory' owner='{{ apacheUser }}' group='{{ apacheUser }}' mode='755' + ignore_errors: yes + + - name: "Check the status of the File Directory" + stat: path='{{ dest }}' + register: directory + + - name: "Move existing File Directory" + shell: rm -rf {{ dir }} && mv {{ dest }} {{ dir }} + when: directory.stat.exists and directory.stat.isdir - - name: "Link webroot to mounted directory" + - name: "Link Site Directory to File Directory" file: - src='{{ drupal_domain.0.mountpoint }}/{{ drupal.id }}/{{ drupal_domain.0.shortname|default("default") }}' - dest='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}' + src='{{ src }}' + dest='{{ dest }}' state='link' owner='{{ apacheUser }}' group='{{ apacheUser }}' mode='755' - force='yes' - - when: drupal_domain.0.mountpoint is defined - -- name: "Ensure File Directories" - file: - dest='{{ dir }}' - state='directory' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='755' - ignore_errors: yes - -- name: "Check the status of the File Directory" - stat: path='{{ dest }}' - register: directory - -- name: "Move existing File Directory" - shell: rm -rf {{ dir }} && mv {{ dest }} {{ dir }} - when: directory.stat.exists and directory.stat.isdir - -- name: "Link Site Directory to File Directory" - file: - src='{{ src }}' - dest='{{ dest }}' - state='link' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='755' - -- name: "Ensure .htaccess" - template: - src='.htaccess' - dest='{{ dir }}/.htaccess' - owner='{{ apacheUser }}' - group='{{ apacheUser }}' - mode='444' + + - name: "Ensure .htaccess" + template: + src='.htaccess' + dest='{{ dir }}/.htaccess' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='444' + + tags: 'SetPermissions' diff --git a/tasks/files_mount.yml b/tasks/files_mount.yml new file mode 100644 index 0000000..023c1cf --- /dev/null +++ b/tasks/files_mount.yml @@ -0,0 +1,20 @@ +--- +# file: roles/drupal/tasks/files_mount.yml + +- name: "Ensure mounted directory" + file: + path='{{ drupal_domain.0.mountpoint }}/{{ drupal.id }}/{{ drupal_domain.0.shortname|default("default") }}' + state='directory' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='755' + +- name: "Link webroot to mounted directory" + file: + src='{{ drupal_domain.0.mountpoint }}/{{ drupal.id }}/{{ drupal_domain.0.shortname|default("default") }}' + dest='{{ webRoot }}/files/{{ drupal_domain.0.shortname|default("default") }}' + state='link' + owner='{{ apacheUser }}' + group='{{ apacheUser }}' + mode='755' + force='yes' diff --git a/tasks/install.yml b/tasks/install.yml index 1056c5e..ae6dc01 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -60,17 +60,15 @@ - include_tasks: install/{{ installSource.mode|default("none") }}.yml when: drupal_first_installation - tags: 'always' -- include_tasks: install/{{ drupal.version|default("d7") }}.yml +- import_tasks: install/{{ drupal.version|default("d7") }}.yml when: drupal_first_installation - tags: 'always' - include_tasks: deploy/{{ installSource.mode|default("none") }}.yml when: drupal_install_drupal tags: 'deploy' -- include_tasks: deploy/{{ drupal.version|default("d7") }}.yml +- import_tasks: deploy/{{ drupal.version|default("d7") }}.yml when: drupal_install_drupal tags: 'deploy' @@ -128,7 +126,7 @@ mode='775' when: drupal.install_extra_dirs|default(true) -- include: mountpoints.yml +- include_tasks: mountpoints.yml with_items: '{{ drupal.mountpoints|default([]) }}' when: drupal.install_extra_dirs|default(true) @@ -190,7 +188,7 @@ tags: 'deploy' when: drush_version_main|default('8') == '9' -- include_tasks: deploy/finalize_{{ drupal.version|default("d7") }}.yml +- import_tasks: deploy/finalize_{{ drupal.version|default("d7") }}.yml when: drupal_install_drupal tags: 'deploy' @@ -282,7 +280,7 @@ tags: 'deploy' - name: "Post Deploy Tasks" - include: deploy/post-tasks.yml + include_tasks: deploy/post-tasks.yml with_items: '{{ drupal.domains }}' loop_control: loop_var: drupal_domain diff --git a/tasks/main.yml b/tasks/main.yml index e186f3a..125e8ef 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -6,8 +6,9 @@ tags: 'always' - block: + - name: "Install Certs" - include: '../../letsencrypt/tasks/cert.yml' + include_tasks: '../../letsencrypt/tasks/cert.yml' with_subelements: - '{{ drupal_settings|default([]) }}' - domains @@ -19,18 +20,23 @@ when: '"letsencrypt" not in excluded_roles and groups.proxyserver is not defined' - block: + - name: "Install Drupal" - include: install.yml + include_tasks: install.yml with_items: '{{ drupal_settings|default([]) }}' loop_control: loop_var: drupal when: limit_site is not defined or drupal.id is not defined or limit_site == drupal.id + tags: + - 'ApacheConfig' + - 'deploy' when: '"drupal" not in excluded_roles and drupal_install_drupal and (collect_config is not defined or not collect_config)' - block: + - name: "Collect Drupal Configuration" - include: collect_config/main.yml + include_tasks: collect_config/main.yml with_items: '{{ drupal_settings|default([]) }}' loop_control: loop_var: drupal diff --git a/tasks/mysql.yml b/tasks/mysql.yml index ccd06a5..1855cf3 100644 --- a/tasks/mysql.yml +++ b/tasks/mysql.yml @@ -1,81 +1,85 @@ --- # file: roles/drupal/tasks/mysql.yml -- set_fact: - db='{{ drupal_domain.db }}' - extra={{ drupal_domain.db.extra|default([]) }} - external={{ drupal_domain.db.external|default([]) }} - external_hosts={{ drupal_domain.db.external_hosts|default([]) }} - tags: 'always' +- block: -- name: "Ensure Database" - mysql_db: - name='{{ db.name }}' - login_user='root' - login_password='{{ mysql_root_password|default("root") }}' - login_host='127.0.0.1' - login_port='{{ db.port|default('3306') }}' - state='present' + - set_fact: + db='{{ drupal_domain.db }}' + extra={{ drupal_domain.db.extra|default([]) }} + external={{ drupal_domain.db.external|default([]) }} + external_hosts={{ drupal_domain.db.external_hosts|default([]) }} + tags: 'always' -- name: "Ensure extra Databases" - mysql_db: - name='{{ item.name }}' - login_user='root' - login_password='{{ mysql_root_password|default("root") }}' - login_host='127.0.0.1' - login_port='{{ item.port|default('3306') }}' - state='present' - with_items: '{{ extra }}' + - name: "Ensure Database" + mysql_db: + name='{{ db.name }}' + login_user='root' + login_password='{{ mysql_root_password|default("root") }}' + login_host='127.0.0.1' + login_port='{{ db.port|default('3306') }}' + state='present' -- name: "Create MySQL User" - mysql_user: - user='{{ db.username|default("root") }}' - password='{{ db.password|default(mysql_root_password|default("root")) }}' - host='{{ item }}' - append_privs=yes - priv='{{ db.name }}.*:ALL' - login_user='root' - login_password='{{ mysql_root_password|default("root") }}' - login_host='127.0.0.1' - login_port='{{ db.port|default('3306') }}' - with_items: - - 'localhost' - - '127.0.0.1' - - '::1' - - '{{ inventory_hostname }}' - when: db.username is defined and db.username != 'root' - ignore_errors: true + - name: "Ensure extra Databases" + mysql_db: + name='{{ item.name }}' + login_user='root' + login_password='{{ mysql_root_password|default("root") }}' + login_host='127.0.0.1' + login_port='{{ item.port|default('3306') }}' + state='present' + with_items: '{{ extra }}' -- name: "Create MySQL User for extra Databases" - mysql_user: - user='{{ item.0.username|default("root") }}' - password='{{ item.0.password|default(mysql_root_password|default("root")) }}' - host='{{ item.1 }}' - append_privs=yes - priv='{{ item.0.name }}.*:ALL' - login_user='root' - login_password='{{ mysql_root_password|default("root") }}' - login_host='127.0.0.1' - login_port='{{ item.0.port|default('3306') }}' - with_nested: - - '{{ extra }}' - - ['localhost', '127.0.0.1', '::1'] - when: item.0.username is defined and item.0.username != 'root' - ignore_errors: true + - name: "Create MySQL User" + mysql_user: + user='{{ db.username|default("root") }}' + password='{{ db.password|default(mysql_root_password|default("root")) }}' + host='{{ item }}' + append_privs=yes + priv='{{ db.name }}.*:ALL' + login_user='root' + login_password='{{ mysql_root_password|default("root") }}' + login_host='127.0.0.1' + login_port='{{ db.port|default('3306') }}' + with_items: + - 'localhost' + - '127.0.0.1' + - '::1' + - '{{ inventory_hostname }}' + when: db.username is defined and db.username != 'root' + ignore_errors: true -- name: "Create external MySQL Users" - mysql_user: - user='{{ item.0.username|default("root") }}' - password='{{ item.0.password|default(mysql_root_password|default("root")) }}' - host='{{ item.1 }}' - append_privs=yes - priv='{{ item.0.priv }}' - login_user='root' - login_password='{{ mysql_root_password|default("root") }}' - login_host='127.0.0.1' - login_port='{{ item.0.port|default('3306') }}' - with_nested: - - '{{ external }}' - - '{{ external_hosts }}' - when: item.0.username is defined and item.0.username != 'root' - ignore_errors: true + - name: "Create MySQL User for extra Databases" + mysql_user: + user='{{ item.0.username|default("root") }}' + password='{{ item.0.password|default(mysql_root_password|default("root")) }}' + host='{{ item.1 }}' + append_privs=yes + priv='{{ item.0.name }}.*:ALL' + login_user='root' + login_password='{{ mysql_root_password|default("root") }}' + login_host='127.0.0.1' + login_port='{{ item.0.port|default('3306') }}' + with_nested: + - '{{ extra }}' + - ['localhost', '127.0.0.1', '::1'] + when: item.0.username is defined and item.0.username != 'root' + ignore_errors: true + + - name: "Create external MySQL Users" + mysql_user: + user='{{ item.0.username|default("root") }}' + password='{{ item.0.password|default(mysql_root_password|default("root")) }}' + host='{{ item.1 }}' + append_privs=yes + priv='{{ item.0.priv }}' + login_user='root' + login_password='{{ mysql_root_password|default("root") }}' + login_host='127.0.0.1' + login_port='{{ item.0.port|default('3306') }}' + with_nested: + - '{{ external }}' + - '{{ external_hosts }}' + when: item.0.username is defined and item.0.username != 'root' + ignore_errors: true + + tags: 'mysql' diff --git a/tasks/scss.yml b/tasks/scss.yml index 7075157..88e4d1b 100644 --- a/tasks/scss.yml +++ b/tasks/scss.yml @@ -1,20 +1,24 @@ --- # file: roles/drupal/tasks/scss.yml -- name: "Make Directory writable" - file: - path: '{{ drupalRoot }}{{ scss_dir }}' - state: 'directory' - owner: 'root' - group: 'root' - mode: 'u+rwX,g+rwX' - recurse: yes +- block: -- name: "Install and update tools, then compile SCSS" - shell: '{{ item }}' - args: - chdir: '{{ drupalRoot }}{{ scss_dir }}' - with_items: - - 'npm install' - - 'bower install --allow-root' - - 'gulp css --env production' + - name: "Make Directory writable" + file: + path: '{{ drupalRoot }}{{ scss_dir }}' + state: 'directory' + owner: 'root' + group: 'root' + mode: 'u+rwX,g+rwX' + recurse: yes + + - name: "Install and update tools, then compile SCSS" + shell: '{{ item }}' + args: + chdir: '{{ drupalRoot }}{{ scss_dir }}' + with_items: + - 'npm install' + - 'bower install --allow-root' + - 'gulp css --env production' + + tags: 'deploy' diff --git a/tasks/users/gitcomposer.yml b/tasks/users/gitcomposer.yml index 3ff6123..9847eb1 100644 --- a/tasks/users/gitcomposer.yml +++ b/tasks/users/gitcomposer.yml @@ -1,23 +1,29 @@ --- # file: roles/drupal/tasks/users/gitcomposer.yml -- name: "Make sure the git group exists" - group: name='{{ drupal.src.name }}' +- block: -- name: "Add users to git group" - user: - name='{{ item }}' - groups='{{ drupal.src.name }}' - append=yes - with_items: '{{ drupal.src.users|default([]) }}' + - name: "Make sure the git group exists" + group: name='{{ drupal.src.name }}' -- name: "File Modes and Ownership for Repository" - file: - path='{{ webRoot }}' - owner='root' - group='{{ drupal.src.name }}' - mode='ug+rw,o+r,o-w' - recurse=yes + - name: "Add users to git group" + user: + name='{{ item }}' + groups='{{ drupal.src.name }}' + append=yes + with_items: '{{ drupal.src.users|default([]) }}' -- name: "Extended File Modes and Ownership for Repository" - command: setfacl -dRm u:root:rwX,g:{{ drupal.src.name }}:rwX,o::rX {{ webRoot }} + - name: "File Modes and Ownership for Repository" + file: + path='{{ webRoot }}' + owner='root' + group='{{ drupal.src.name }}' + mode='ug+rw,o+r,o-w' + recurse=yes + + - name: "Extended File Modes and Ownership for Repository" + command: setfacl -dRm u:root:rwX,g:{{ drupal.src.name }}:rwX,o::rX {{ webRoot }} + + tags: + - 'SetPermissions' + - 'cron' diff --git a/tasks/users/gitscript.yml b/tasks/users/gitscript.yml index 48cd598..32e78a5 100644 --- a/tasks/users/gitscript.yml +++ b/tasks/users/gitscript.yml @@ -1,48 +1,32 @@ --- # file: roles/drupal/tasks/users/gitscript.yml -- name: "Make sure the git group exists" - group: name='{{ drupal.src.name }}' - -- name: "Add users to git group" - user: - name='{{ item }}' - groups='{{ drupal.src.name }}' - append=yes - with_items: '{{ drupal.src.users|default([]) }}' +- block: -- name: "File Modes and Ownership for Repository" - file: - path='{{ webRoot }}{{ drupal.src.git.target }}' - owner='root' - group='{{ drupal.src.name }}' - mode='ug+rw,o+r,o-w' - recurse=yes + - name: "Make sure the git group exists" + group: name='{{ drupal.src.name }}' -- name: "Extended File Modes and Ownership for Repository" - command: setfacl -dRm u:root:rwX,g:{{ drupal.src.name }}:rwX,o::rX {{ webRoot }}{{ drupal.src.git.target }} + - name: "Add users to git group" + user: + name='{{ item }}' + groups='{{ drupal.src.name }}' + append=yes + with_items: '{{ drupal.src.users|default([]) }}' -- block: - - - name: "Create Update Script" - template: - src='scripts/update/gitscript.jinja2' - dest='{{ webRoot }}/.update' + - name: "File Modes and Ownership for Repository" + file: + path='{{ webRoot }}{{ drupal.src.git.target }}' owner='root' - group='root' - mode='755' + group='{{ drupal.src.name }}' + mode='ug+rw,o+r,o-w' + recurse=yes + + - name: "Extended File Modes and Ownership for Repository" + command: setfacl -dRm u:root:rwX,g:{{ drupal.src.name }}:rwX,o::rX {{ webRoot }}{{ drupal.src.git.target }} - - name: "Crontab for Update Script" - cron: - name='Drupal Update {{ drupal.src.name }}' - month='{{ drupal.src.cron.month|default(omit) }}' - day='{{ drupal.src.cron.day|default(omit) }}' - weekday='{{ drupal.src.cron.weekday|default(omit) }}' - hour='{{ drupal.src.cron.hour|default(omit) }}' - minute='{{ drupal.src.cron.minute|default(omit) }}' - job='{{ webRoot }}/.update >>{{ webRoot }}/../log/git-update.log 2>&1' - user='root' - disabled='{{ crons_disabled|default(false) }}' + - import_tasks: gitscript_cron.yml + when: drupal.src.cron is defined - when: drupal.src.cron is defined - tags: 'cron' + tags: + - 'SetPermissions' + - 'cron' diff --git a/tasks/users/gitscript_cron.yml b/tasks/users/gitscript_cron.yml new file mode 100644 index 0000000..7ed550c --- /dev/null +++ b/tasks/users/gitscript_cron.yml @@ -0,0 +1,22 @@ +--- +# file: roles/drupal/tasks/users/gitscript_cron.yml + +- name: "Create Update Script" + template: + src='scripts/update/gitscript.jinja2' + dest='{{ webRoot }}/.update' + owner='root' + group='root' + mode='755' + +- name: "Crontab for Update Script" + cron: + name='Drupal Update {{ drupal.src.name }}' + month='{{ drupal.src.cron.month|default(omit) }}' + day='{{ drupal.src.cron.day|default(omit) }}' + weekday='{{ drupal.src.cron.weekday|default(omit) }}' + hour='{{ drupal.src.cron.hour|default(omit) }}' + minute='{{ drupal.src.cron.minute|default(omit) }}' + job='{{ webRoot }}/.update >>{{ webRoot }}/../log/git-update.log 2>&1' + user='root' + disabled='{{ crons_disabled|default(false) }}' -- GitLab