From 17a753c7d257809f8896b73b34a9bf5f764f7ec3 Mon Sep 17 00:00:00 2001 From: Scott Walkinshaw Date: Sat, 8 Apr 2017 17:40:10 -0400 Subject: [PATCH] Add ansible_local support for non-Windows Previously only Windows would use Vagrant's `ansible_local` provisioner. But it's a much easier experience to get started in development since it skips the Ansible requirement. This automatically uses the `ansible_local` provisioner if `ansible-playbook` does not exist on the host machine. --- CHANGELOG.md | 1 + README.md | 11 ++++++----- Vagrantfile | 6 +++--- lib/trellis/vagrant.rb | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4608ff18d0..82a352e6b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### HEAD +* Add ansible_local support for non-Windows ([#824](https://github.com/roots/trellis/pull/824)) * Add `fastcgi_read_timeout` to Nginx config ([#860](https://github.com/roots/trellis/pull/860)) * Accommodate child themes: Update WP `stylesheet_root` separately ([#850](https://github.com/roots/trellis/pull/850)) * Deploys: `--skip-themes` when updating WP `template_root` ([#849](https://github.com/roots/trellis/pull/849)) diff --git a/README.md b/README.md index ede7f1335b..796f26f4d7 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,14 @@ Trellis will configure a server with the following and more: * Fail2ban * ferm +## Documentation + +Full documentation is available at [https://roots.io/trellis/docs/](https://roots.io/trellis/docs/). + ## Requirements Make sure all dependencies have been installed before moving on: -* [Ansible](http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-pip) >= 2.2 * [Virtualbox](https://www.virtualbox.org/wiki/Downloads) >= 4.3.10 * [Vagrant](https://www.vagrantup.com/downloads.html) >= 1.8.5 @@ -56,10 +59,6 @@ See a complete working example in the [roots-example-project.com repo](https://g Windows user? [Read the Windows docs](https://roots.io/trellis/docs/windows/) for slightly different installation instructions. VirtualBox is known to have poor performance in Windows — use VMware or [see some possible solutions](https://discourse.roots.io/t/virtualbox-performance-in-windows/3932). -## Documentation - -Trellis documentation is available at [https://roots.io/trellis/docs/](https://roots.io/trellis/docs/). - ## Local development setup 1. Configure your WordPress sites in `group_vars/development/wordpress_sites.yml` and in `group_vars/development/vault.yml` @@ -69,6 +68,8 @@ Trellis documentation is available at [https://roots.io/trellis/docs/](https://r ## Remote server setup (staging/production) +For remote servers, installing Ansible locally is an additional requirement. See the [docs](https://roots.io/trellis/docs/remote-server-setup/#requirements) for more information. + A base Ubuntu 16.04 server is required for setting up remote servers. OS X users must have [passlib](http://pythonhosted.org/passlib/install.html#installation-instructions) installed. 1. Configure your WordPress sites in `group_vars//wordpress_sites.yml` and in `group_vars//vault.yml` (see the [Vault docs](https://roots.io/trellis/docs/vault/) for how to encrypt files containing passwords) diff --git a/Vagrantfile b/Vagrantfile index 4102f4f804..8982985d9b 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -91,11 +91,11 @@ Vagrant.configure('2') do |config| end end - provisioner = Vagrant::Util::Platform.windows? ? :ansible_local : :ansible - provisioning_path = Vagrant::Util::Platform.windows? ? ANSIBLE_PATH_ON_VM : ANSIBLE_PATH + provisioner = local_provisioning? ? :ansible_local : :ansible + provisioning_path = local_provisioning? ? ANSIBLE_PATH_ON_VM : ANSIBLE_PATH config.vm.provision provisioner do |ansible| - if Vagrant::Util::Platform.windows? + if local_provisioning? ansible.install_mode = 'pip' ansible.provisioning_path = provisioning_path ansible.version = vconfig.fetch('vagrant_ansible_version') diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index d25b44fe59..bc036b8afd 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -62,6 +62,10 @@ def load_wordpress_sites wordpress_sites end +def local_provisioning? + @local_provisioning ||= Vagrant::Util::Platform.windows? || !which('ansible-playbook') || ENV['FORCE_ANSIBLE_LOCAL'] +end + def local_site_path(site) File.expand_path(site['local_path'], ANSIBLE_PATH) end @@ -90,3 +94,16 @@ def post_up_message def remote_site_path(site_name, site) "/srv/www/#{site_name}/#{site['current_path'] || 'current'}" end + +def which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + + paths = ENV['PATH'].split(File::PATH_SEPARATOR).flat_map do |path| + exts.map { |ext| File.join(path, "#{cmd}#{ext}") } + end + + paths.any? do |path| + next unless File.executable?(path) && !File.directory?(path) + system("#{path} --help", %i(out err) => File::NULL) + end +end