Skip to content

Commit 17a753c

Browse files
committed
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.
1 parent bc698fc commit 17a753c

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### HEAD
2+
* Add ansible_local support for non-Windows ([#824](https://github.com/roots/trellis/pull/824))
23
* Add `fastcgi_read_timeout` to Nginx config ([#860](https://github.com/roots/trellis/pull/860))
34
* Accommodate child themes: Update WP `stylesheet_root` separately ([#850](https://github.com/roots/trellis/pull/850))
45
* Deploys: `--skip-themes` when updating WP `template_root` ([#849](https://github.com/roots/trellis/pull/849))

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ Trellis will configure a server with the following and more:
2727
* Fail2ban
2828
* ferm
2929

30+
## Documentation
31+
32+
Full documentation is available at [https://roots.io/trellis/docs/](https://roots.io/trellis/docs/).
33+
3034
## Requirements
3135

3236
Make sure all dependencies have been installed before moving on:
3337

34-
* [Ansible](http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-pip) >= 2.2
3538
* [Virtualbox](https://www.virtualbox.org/wiki/Downloads) >= 4.3.10
3639
* [Vagrant](https://www.vagrantup.com/downloads.html) >= 1.8.5
3740

@@ -56,10 +59,6 @@ See a complete working example in the [roots-example-project.com repo](https://g
5659

5760
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).
5861

59-
## Documentation
60-
61-
Trellis documentation is available at [https://roots.io/trellis/docs/](https://roots.io/trellis/docs/).
62-
6362
## Local development setup
6463

6564
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
6968

7069
## Remote server setup (staging/production)
7170

71+
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.
72+
7273
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.
7374

7475
1. Configure your WordPress sites in `group_vars/<environment>/wordpress_sites.yml` and in `group_vars/<environment>/vault.yml` (see the [Vault docs](https://roots.io/trellis/docs/vault/) for how to encrypt files containing passwords)

Vagrantfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ Vagrant.configure('2') do |config|
9191
end
9292
end
9393

94-
provisioner = Vagrant::Util::Platform.windows? ? :ansible_local : :ansible
95-
provisioning_path = Vagrant::Util::Platform.windows? ? ANSIBLE_PATH_ON_VM : ANSIBLE_PATH
94+
provisioner = local_provisioning? ? :ansible_local : :ansible
95+
provisioning_path = local_provisioning? ? ANSIBLE_PATH_ON_VM : ANSIBLE_PATH
9696

9797
config.vm.provision provisioner do |ansible|
98-
if Vagrant::Util::Platform.windows?
98+
if local_provisioning?
9999
ansible.install_mode = 'pip'
100100
ansible.provisioning_path = provisioning_path
101101
ansible.version = vconfig.fetch('vagrant_ansible_version')

lib/trellis/vagrant.rb

+17
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def load_wordpress_sites
6262
wordpress_sites
6363
end
6464

65+
def local_provisioning?
66+
@local_provisioning ||= Vagrant::Util::Platform.windows? || !which('ansible-playbook') || ENV['FORCE_ANSIBLE_LOCAL']
67+
end
68+
6569
def local_site_path(site)
6670
File.expand_path(site['local_path'], ANSIBLE_PATH)
6771
end
@@ -90,3 +94,16 @@ def post_up_message
9094
def remote_site_path(site_name, site)
9195
"/srv/www/#{site_name}/#{site['current_path'] || 'current'}"
9296
end
97+
98+
def which(cmd)
99+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
100+
101+
paths = ENV['PATH'].split(File::PATH_SEPARATOR).flat_map do |path|
102+
exts.map { |ext| File.join(path, "#{cmd}#{ext}") }
103+
end
104+
105+
paths.any? do |path|
106+
next unless File.executable?(path) && !File.directory?(path)
107+
system("#{path} --help", %i(out err) => File::NULL)
108+
end
109+
end

0 commit comments

Comments
 (0)