From 235da6d1118d62a2065545a8391a04d73c98e42c Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 4 Aug 2016 18:50:07 +0200 Subject: [PATCH] library/roles/drupal-org: Add tasks that install drush. Add composer as dependency. --- drupal-org/defaults/main.yml | 3 ++ drupal-org/meta/main.yml | 4 ++ drupal-org/tasks/drupal-main.yml | 75 +++++++++++++++++++++++++++++++ drupal-org/tasks/drush.yml | 7 +++ drupal-org/tasks/main.yml | 77 ++------------------------------ 5 files changed, 92 insertions(+), 74 deletions(-) create mode 100644 drupal-org/meta/main.yml create mode 100644 drupal-org/tasks/drupal-main.yml create mode 100644 drupal-org/tasks/drush.yml diff --git a/drupal-org/defaults/main.yml b/drupal-org/defaults/main.yml index 50413cf1..756050f9 100644 --- a/drupal-org/defaults/main.yml +++ b/drupal-org/defaults/main.yml @@ -5,6 +5,7 @@ drupal_version: '{{ drupal_major_ver }}.1.7' drupal_dist_name: 'drupal-{{ drupal_version }}' drupal_dist_file: '{{ drupal_dist_name }}.tar.gz' drupal_tar_url: 'http://ftp.drupal.org/files/projects/{{ drupal_dist_file }}' +drupal_php_user: drupal drupal_download_dir: /srv/drupal drupal_install_dir: /var/www @@ -25,3 +26,5 @@ drupal_php_prereq: - php-xml-serializer - imagemagick +drupal_install_drush: True +drupal_drush_version: '{{ drupal_major }}.*' diff --git a/drupal-org/meta/main.yml b/drupal-org/meta/main.yml new file mode 100644 index 00000000..05a6e2b4 --- /dev/null +++ b/drupal-org/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: + - { role: '../../library/roles/composer', when: drupal_install_drush } + diff --git a/drupal-org/tasks/drupal-main.yml b/drupal-org/tasks/drupal-main.yml new file mode 100644 index 00000000..520cfb76 --- /dev/null +++ b/drupal-org/tasks/drupal-main.yml @@ -0,0 +1,75 @@ +--- +- name: Install the drupal php prerequisites + apt: name={{ item }} state=latest update_cache=yes cache_valid_time=3600 + with_items: '{{ drupal_php_prereq }}' + tags: drupal + +- name: Ensure that the download and install dirs exist + file: path={{ item }} state=directory + with_items: + - '{{ drupal_download_dir }}' + - '{{ drupal_install_dir }}' + tags: drupal + +- name: Download the drupal tar file + get_url: url={{ drupal_tar_url }} dest={{ drupal_download_dir }} + when: not drupal_install_deb + register: drupal_download + tags: drupal + +- name: Install the drupal deb package + apt: name=drupal state=installed + when: drupal_install_deb + tags: [ 'drupal', 'drupal_deb' ] + +- name: Unpack the drupal tar file + unarchive: copy=no src={{ drupal_download_dir }}/{{ drupal_dist_file }} dest={{ drupal_download_dir }} + when: ( drupal_download | changed ) + tags: drupal + +- name: Move the drupal files to the right place + command: cp -a {{ drupal_download_dir }}/{{ drupal_dist_name }} {{ drupal_install_dir }}/{{ item.virthost }} + args: + creates: '{{ drupal_install_dir }}/{{ item.virthost }}/index.php' + with_items: '{{ phpfpm_pools }}' + when: ( drupal_download | changed ) + register: unpack_drupal + tags: drupal + +- name: Create the default settings file + command: cp {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/default.settings.php {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/settings.php + args: + creates: '{{ drupal_install_dir }}/{{ item.virthost }}/sites/default/settings.php' + with_items: '{{ phpfpm_pools }}' + when: + - ( unpack_drupal | changed ) + - '{{ drupal_major_ver }} >= 8' + tags: drupal + +- name: Create the default services file + command: cp {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/default.services.yml {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/services.yml + args: + creates: '{{ drupal_install_dir }}/{{ item.virthost }}/sites/default/services.yml' + with_items: '{{ phpfpm_pools }}' + when: + - ( unpack_drupal | changed ) + - '{{ drupal_major_ver }} >= 8' + tags: drupal + +- name: Create the files directory + file: dest={{ drupal_install_dir }}/{{ item.virthost }}/sites/default/files owner={{ item.user }} group={{ item.group }} mode=0770 state=directory + with_items: '{{ phpfpm_pools }}' + when: ( unpack_drupal | changed ) + tags: drupal + +- name: Set the correct ownership of the drupal files + file: dest={{ drupal_install_dir }}/{{ item.virthost }} owner={{ item.user }} group={{ item.group }} recurse=yes state=directory + with_items: '{{ phpfpm_pools }}' + when: ( unpack_drupal | changed ) + tags: drupal + +- name: Remove the original drupal unpacked distribution + file: dest={{ drupal_download_dir }}/{{ drupal_dist_name }} state=absent + when: ( unpack_drupal | changed ) + tags: drupal + diff --git a/drupal-org/tasks/drush.yml b/drupal-org/tasks/drush.yml new file mode 100644 index 00000000..c077c481 --- /dev/null +++ b/drupal-org/tasks/drush.yml @@ -0,0 +1,7 @@ +--- +- name: Install drush + become: True + become_user: '{{ item.user }}' + composer: command=require arguments=drush/drush:{{ drupal_drush_version }} prefer_dist=yes working_dir={{ item.doc_root }} + with_items: '{{ phpfpm_pools }}' + tags: ['drupal', 'drush' ] diff --git a/drupal-org/tasks/main.yml b/drupal-org/tasks/main.yml index 520cfb76..47638945 100644 --- a/drupal-org/tasks/main.yml +++ b/drupal-org/tasks/main.yml @@ -1,75 +1,4 @@ --- -- name: Install the drupal php prerequisites - apt: name={{ item }} state=latest update_cache=yes cache_valid_time=3600 - with_items: '{{ drupal_php_prereq }}' - tags: drupal - -- name: Ensure that the download and install dirs exist - file: path={{ item }} state=directory - with_items: - - '{{ drupal_download_dir }}' - - '{{ drupal_install_dir }}' - tags: drupal - -- name: Download the drupal tar file - get_url: url={{ drupal_tar_url }} dest={{ drupal_download_dir }} - when: not drupal_install_deb - register: drupal_download - tags: drupal - -- name: Install the drupal deb package - apt: name=drupal state=installed - when: drupal_install_deb - tags: [ 'drupal', 'drupal_deb' ] - -- name: Unpack the drupal tar file - unarchive: copy=no src={{ drupal_download_dir }}/{{ drupal_dist_file }} dest={{ drupal_download_dir }} - when: ( drupal_download | changed ) - tags: drupal - -- name: Move the drupal files to the right place - command: cp -a {{ drupal_download_dir }}/{{ drupal_dist_name }} {{ drupal_install_dir }}/{{ item.virthost }} - args: - creates: '{{ drupal_install_dir }}/{{ item.virthost }}/index.php' - with_items: '{{ phpfpm_pools }}' - when: ( drupal_download | changed ) - register: unpack_drupal - tags: drupal - -- name: Create the default settings file - command: cp {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/default.settings.php {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/settings.php - args: - creates: '{{ drupal_install_dir }}/{{ item.virthost }}/sites/default/settings.php' - with_items: '{{ phpfpm_pools }}' - when: - - ( unpack_drupal | changed ) - - '{{ drupal_major_ver }} >= 8' - tags: drupal - -- name: Create the default services file - command: cp {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/default.services.yml {{ drupal_install_dir }}/{{ item.virthost }}/sites/default/services.yml - args: - creates: '{{ drupal_install_dir }}/{{ item.virthost }}/sites/default/services.yml' - with_items: '{{ phpfpm_pools }}' - when: - - ( unpack_drupal | changed ) - - '{{ drupal_major_ver }} >= 8' - tags: drupal - -- name: Create the files directory - file: dest={{ drupal_install_dir }}/{{ item.virthost }}/sites/default/files owner={{ item.user }} group={{ item.group }} mode=0770 state=directory - with_items: '{{ phpfpm_pools }}' - when: ( unpack_drupal | changed ) - tags: drupal - -- name: Set the correct ownership of the drupal files - file: dest={{ drupal_install_dir }}/{{ item.virthost }} owner={{ item.user }} group={{ item.group }} recurse=yes state=directory - with_items: '{{ phpfpm_pools }}' - when: ( unpack_drupal | changed ) - tags: drupal - -- name: Remove the original drupal unpacked distribution - file: dest={{ drupal_download_dir }}/{{ drupal_dist_name }} state=absent - when: ( unpack_drupal | changed ) - tags: drupal - +- include: drupal-main.yml +- include: drush.yml + when: drupal_install_drush