Merge branch 'auto-hostname' into 'master'

Complete provisioning and automate system name

See merge request agaric/sites/agaric-com!3
This commit is contained in:
Chris Thompson 2018-08-24 03:18:00 +00:00
commit 853eb39c55
8 changed files with 158 additions and 74 deletions

6
box/Vagrantfile vendored
View file

@ -27,6 +27,10 @@ vconfig = load_config([
"#{host_config_dir}/local.config.yml"
])
# Override all drupalvm.test values according to project root:
require (File.expand_path('drutopiavm', host_config_dir))
set_overrides_per_project(vconfig)
provisioner = vconfig['force_ansible_local'] ? :ansible_local : vagrant_provisioner
if provisioner == :ansible
playbook = "#{host_drupalvm_dir}/provisioning/playbook.yml"
@ -46,7 +50,7 @@ Vagrant.configure('2') do |config|
# Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134
config.vm.define vconfig['vagrant_machine_name']
# Networking configuration.
# Networking configuration
config.vm.hostname = vconfig['vagrant_hostname']
config.vm.network :private_network,
ip: vconfig['vagrant_ip'],

View file

@ -9,10 +9,12 @@
vagrant_box: geerlingguy/debian9
# If you need to run multiple instances of Drupal VM, set a unique hostname,
# and machine name
vagrant_hostname: agaric.local
vagrant_machine_name: agaric-com-vm
# These variables are no longer honored. In order to use them specifically,
# revert the changes to use vconfig values in <project_root>/box/Vagrant
# And disable the pre-tasks
# vagrant_hostname: drutopia.local
# vagrant_machine_name: drutopia-com-vm
# You can specify an IP, or else the vagrant-auto_network will set it for you:
vagrant_ip: 0.0.0.0
@ -36,7 +38,7 @@ vagrant_plugins:
# Setting theme to empty will skip sass step:
# (drutopia's default theme, octavia, is included)
theme:
theme:
# Set this to 'false' if you are using a different site deployment strategy and
# would like to configure 'vagrant_synced_folders' and 'apache_vhosts' manually.
@ -150,7 +152,7 @@ installed_extras:
- mailhog
# - memcached
# - newrelic
# - nodejs
- nodejs
- pimpmylog
# - redis
# - ruby
@ -219,7 +221,7 @@ adminer_install_filename: index.php
# Node.js configuration (if enabled above).
# Valid examples: "0.10", "0.12", "4.x", "5.x", "6.x".
nodejs_version: "6.x"
nodejs_version: "8.x"
nodejs_npm_global_packages: []
nodejs_install_npm_user: "{{ drupalvm_user }}"
npm_config_prefix: "/home/{{ drupalvm_user }}/.npm-global"
@ -269,4 +271,5 @@ hostname_configure: true
hostname_fqdn: "{{ vagrant_hostname }}"
ssh_home: "{{ drupal_core_path }}"
post_provision_tasks_dir: ../../provisioning/tasks/*.yml
post_provision_tasks_dir: ../../provisioning/box/post-tasks/*.yml
pre_provision_tasks_dir: ../../provisioning/box/pre-tasks/*.yml

View file

@ -0,0 +1,15 @@
def set_overrides_per_project(config)
# Acquire a hostname from the project root
project_dir_name = File.basename(ENV['DRUPALVM_PROJECT_ROOT']).gsub("_", "-")
host_name = "#{project_dir_name}.test"
# Override all vconfig values with the new names
config['vagrant_hostname'] = host_name
config['vagrant_machine_name'] = "#{project_dir_name}-vm"
config['drupal_domain'] = host_name
config['hostname_fqdn'] =
config['apache_vhosts'].each do |host|
host['servername'].sub!('drupalvm.test', host_name)
host['serveralias'].gsub!('drupalvm.test', host_name) if host['serveralias']
end
end

View file

@ -0,0 +1,78 @@
---
- name: determine status of settings location
stat:
path: "{{ drupal_core_path }}/sites/default"
register: stat_result
- name: ensure settings location is writable
file:
path: "{{ drupal_core_path }}/sites/default"
mode: 0775
state: directory
when: stat_result.stat.exists == true and stat_result.stat.writeable == false
- name: ensure settings file is still writable
file:
path: "{{ drupal_core_path }}/sites/default/settings.php"
mode: 0664
state: file
when: stat_result.stat.exists == true and stat_result.stat.writeable == false
- name: Run composer install.
command: "composer install"
args:
chdir: "{{ drupal_composer_install_dir }}"
- name: install default settings.php
copy:
src: "{{ drupal_core_path }}/sites/default/default.settings.php"
dest: "{{ drupal_core_path }}/sites/default/settings.php"
remote_src: true
- name: enable settings.local.php include_tasks
blockinfile:
path: "{{ drupal_core_path }}/sites/default/settings.php"
marker: "/* {mark} ANSIBLE MANAGED BLOCK: LOCAL INCLUDE */"
insertafter: EOF
content: |1+
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
include $app_root . '/' . $site_path . '/settings.local.php';
}
- name: create settings.local.php
template:
src: "settings.local.php.j2"
dest: "{{ drupal_core_path }}/sites/default/settings.local.php"
- name: Check if site is already installed.
command: "{{ drupal_composer_install_dir }}/vendor/bin/drush --root={{ drupal_core_path}}/ status bootstrap"
args:
chdir: "{{ drupal_core_path }}"
register: drupal_site_installed
failed_when: "drupal_site_installed.stdout is undefined"
changed_when: false
become: no
- name: Install Drupal with drush.
command: >
{{ drupal_composer_install_dir }}/vendor/bin/drush site-install -y
--root={{ drupal_core_path }}
--site-name={{ drupal_site_name }}
--account-name={{ drupal_account_name }}
--account-pass={{ drupal_account_pass }}
--site-mail={{ drupal_account_email }}
args:
chdir: "{{ drupal_core_path }}"
become: no
when: "force_reinstall|default(false) or 'Drupal bootstrap' not in drupal_site_installed.stdout"
- name: Install theme build dependencies
npm:
path: "{{ drupal_core_path }}/themes/custom/agarica/patternlibrary"
state: present
- name: Build theme artifacts
command: grunt kss
args:
chdir: "{{ drupal_core_path }}/themes/custom/agarica/patternlibrary"
ignore_errors: yes

View file

@ -0,0 +1,30 @@
<?php
/**
* @file
* Settings for the hosted environment.
*/
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => '{{ drupal_db_name }}',
'username' => '{{ drupal_db_user }}',
'password' => '{{ drupal_db_password }}',
'host' => '{{ drupal_db_host|default(localhost) }}',
'prefix' => '',
);
$settings['trusted_host_patterns'] = array(
'^(.*\.)*{{ vagrant_hostname|default("*")|replace(".", "\.") }}$'
);
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
$config_directories = array(
CONFIG_SYNC_DIRECTORY => '../custom/config/sync',
);
$config['system.site']['name'] = '{{ drupal_site_name }}';
$settings['hash_salt'] = 's@lt1s4SQLn0t4$na1l$';

View file

@ -0,0 +1,19 @@
---
- name: get root folder of project
shell: pwd
register: proj_root
args:
chdir: "{{ playbook_dir }}/../../"
delegate_to: localhost
become: false
- name: remove underscores from folder name
set_fact:
proj_root_safe: "{{ proj_root.stdout|basename|replace('_','-') }}"
# These values are NOT honored by Vagrant, but are still necessary for DrupalVM
# See also provisioning/box/config
- name: set vagrant hostname according to the project folder
set_fact:
vagrant_hostname: "{{ proj_root_safe }}.test"
vagrant_machine_name: "{{ proj_root_safe }}-vm"

View file

@ -1,65 +0,0 @@
---
- name: Run composer install.
command: "composer install"
args:
chdir: "{{ drupal_composer_install_dir }}"
- name: Check if site is already installed.
command: "{{ drupal_composer_install_dir }}/vendor/bin/drush --root={{ drupal_composer_install_dir }}/web/ status bootstrap"
args:
chdir: "{{ drupal_composer_install_dir }}/web"
register: drupal_site_installed
failed_when: "drupal_site_installed.stdout is undefined"
changed_when: false
become: no
# - name: Ensure /etc/drush folder exists
# file:
# name: /etc/drush
# state: directory
# group: root
# owner: root
# mode: 0755
# become: yes
#
# - name: Install drushrc.php
# copy:
# src: drushrc.php
# dest: /etc/drush/drushrc.php
# owner: root
# group: root
# mode: 0755
# backup: no
# become: yes
# - name: Add RewriteMap to vhost.conf
# lineinfile:
# path: /etc/apache2/sites-enabled/vhosts.conf
# line: "RewriteMap legacy \"txt:{{ web_root}}/redirect/legacy.txt\""
# insertafter: "DocumentRoot \"{{ web_root }}/web\""
# become: yes
- name: Install Drupal with drush.
command: >
{{ drupal_composer_install_dir }}/vendor/bin/drush site-install -y
--root={{ drupal_composer_install_dir }}/web
--site-name={{ drupal_site_name }}
--account-name={{ drupal_account_name }}
--account-pass={{ drupal_account_pass }}
--site-mail={{ drupal_account_email }}
args:
chdir: "{{ drupal_composer_install_dir }}/web"
become: no
when: "force_reinstall|default(false) or 'Drupal bootstrap' not in drupal_site_installed.stdout"
- name: Run sass
command: sassc sass/styles.scss css/styles.css
args:
chdir: "{{ drupal_composer_install_dir }}/web/themes/{{ theme }}/"
when: theme != ""
# - name: Ensure ansible is installed
# apt:
# name: ansible
# state: latest
# become: yes