From bc52c726456844bc7f6cdf1c3768c868e2732bc5 Mon Sep 17 00:00:00 2001 From: kalenjohnson Date: Mon, 7 Nov 2016 23:41:18 -0800 Subject: [PATCH 1/4] Switch to ansible_local provisioner, remove Windows shell script --- Vagrantfile | 31 +++++++++++++++++++++++-------- ansible.cfg | 1 - windows.sh | 49 ------------------------------------------------- 3 files changed, 23 insertions(+), 58 deletions(-) delete mode 100644 windows.sh diff --git a/Vagrantfile b/Vagrantfile index ff7bbfc861..2e3ba8c684 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -87,19 +87,34 @@ Vagrant.configure('2') do |config| end end + groups = { + 'web' => ['default'], + 'development' => ['default'] + } + if Vagrant::Util::Platform.windows? - config.vm.provision :shell do |sh| - sh.path = File.join(ANSIBLE_PATH, 'windows.sh') - sh.args = [Vagrant::VERSION] - sh.keep_color = true + config.vm.provision "ansible_local" do |ansible| + ansible.install_mode = 'pip' + ansible.version = '2.1.3' + ansible.galaxy_roles_path = 'vendor/roles' + ansible.galaxy_role_file = 'requirements.yml' + ansible.playbook = 'dev.yml' + ansible.groups = groups + + if tags = ENV['ANSIBLE_TAGS'] + ansible.tags = tags + end + + ansible.extra_vars = {'vagrant_version' => Vagrant::VERSION} + if vars = ENV['ANSIBLE_VARS'] + extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }] + ansible.extra_vars.merge(extra_vars) + end end else config.vm.provision :ansible do |ansible| ansible.playbook = File.join(ANSIBLE_PATH, 'dev.yml') - ansible.groups = { - 'web' => ['default'], - 'development' => ['default'] - } + ansible.groups = groups if tags = ENV['ANSIBLE_TAGS'] ansible.tags = tags diff --git a/ansible.cfg b/ansible.cfg index 63876eae63..78bbb2432d 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -6,7 +6,6 @@ force_color = True force_handlers = True inventory = hosts nocows = 1 -roles_path = vendor/roles vars_plugins = ~/.ansible/plugins/vars_plugins/:/usr/share/ansible_plugins/vars_plugins:lib/trellis/plugins/vars [ssh_connection] diff --git a/windows.sh b/windows.sh deleted file mode 100644 index 56697ff942..0000000000 --- a/windows.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# Windows provisioner for Trellis -# heavily modified and based on KSid/windows-vagrant-ansible -# @author Andrea Brandi -# @version 1.0 - -ANSIBLE_PATH="$(find /vagrant -name 'windows.sh' -printf '%h' -quit)" -export PYTHONUNBUFFERED=1 - -# Create an ssh key if not already created. -if [ ! -f ~/.ssh/id_rsa ]; then - echo -e "\n\n\n" | ssh-keygen -t rsa -fi - -# Check SSH forwarding agent -echo ' -printf "\033[1;33m" -if ! ssh-add -l >/dev/null; then - printf "See: https://roots.io/trellis/docs/windows/#ssh-forwarding" -fi -printf "\033[0m\n\n" -' >> /home/vagrant/.profile - -# Check that add-apt-repository is installed for non-standard Vagrant boxes -if [ ! -f /usr/bin/add-apt-repository ]; then - sudo apt-get -y update - echo "Adding add-apt-repository..." - sudo apt-get -y install software-properties-common -fi - -# Install Ansible and its dependencies if not installed. -if [ ! -f /usr/bin/ansible ]; then - echo "Installing pip..." - sudo apt-get -y update - sudo apt-get -y install python-pip libssl-dev libffi-dev - echo "Installing Ansible with pip..." - sudo pip install ansible=='2.0.2.0' - sudo pip install markupsafe -fi - -if [ ! -d ${ANSIBLE_PATH}/vendor ]; then - echo "Running Ansible Galaxy install" - ansible-galaxy install -r ${ANSIBLE_PATH}/requirements.yml -p ${ANSIBLE_PATH}/vendor/roles -fi - -echo "Running Ansible Playbooks" -cd ${ANSIBLE_PATH}/ -ansible-playbook dev.yml -e vagrant_version=$1 From 6642913febe90aea6231d4f5a246d05dae214ba1 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Sun, 27 Nov 2016 21:10:21 -0700 Subject: [PATCH 2/4] Re-add roles_paths --- ansible.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible.cfg b/ansible.cfg index 78bbb2432d..63876eae63 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -6,6 +6,7 @@ force_color = True force_handlers = True inventory = hosts nocows = 1 +roles_path = vendor/roles vars_plugins = ~/.ansible/plugins/vars_plugins/:/usr/share/ansible_plugins/vars_plugins:lib/trellis/plugins/vars [ssh_connection] From de90177f2a3915be149c0f1bbc0edee860e5ffd2 Mon Sep 17 00:00:00 2001 From: Phil Nelson Date: Mon, 28 Nov 2016 02:34:56 -0700 Subject: [PATCH 3/4] Combine provisioner code in Vagrantfile --- Vagrantfile | 60 ++++++++++++++----------------------- roles/common/tasks/main.yml | 6 ++++ 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 2e3ba8c684..691d2818c5 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -30,10 +30,6 @@ else fail_with_message "#{config_file} was not found. Please set `ANSIBLE_PATH` in your Vagrantfile." end -if !Dir.exists?(ENV['ANSIBLE_ROLES_PATH']) && !Vagrant::Util::Platform.windows? - fail_with_message "You are missing the required Ansible Galaxy roles, please install them with this command:\nansible-galaxy install -r requirements.yml" -end - Vagrant.require_version '>= 1.8.5' Vagrant.configure('2') do |config| @@ -87,44 +83,32 @@ Vagrant.configure('2') do |config| end end - groups = { - 'web' => ['default'], - 'development' => ['default'] - } - - if Vagrant::Util::Platform.windows? - config.vm.provision "ansible_local" do |ansible| + provisioner = Vagrant::Util::Platform.windows? ? :ansible_local : :ansible + provisioning_path = Vagrant::Util::Platform.windows? ? ANSIBLE_PATH.sub(__dir__, '/vagrant') : ANSIBLE_PATH + config.vm.provision provisioner do |ansible| + if Vagrant::Util::Platform.windows? ansible.install_mode = 'pip' - ansible.version = '2.1.3' - ansible.galaxy_roles_path = 'vendor/roles' - ansible.galaxy_role_file = 'requirements.yml' - ansible.playbook = 'dev.yml' - ansible.groups = groups - - if tags = ENV['ANSIBLE_TAGS'] - ansible.tags = tags - end - - ansible.extra_vars = {'vagrant_version' => Vagrant::VERSION} - if vars = ENV['ANSIBLE_VARS'] - extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }] - ansible.extra_vars.merge(extra_vars) - end + ansible.provisioning_path = provisioning_path + ansible.version = '2.2.0' end - else - config.vm.provision :ansible do |ansible| - ansible.playbook = File.join(ANSIBLE_PATH, 'dev.yml') - ansible.groups = groups - if tags = ENV['ANSIBLE_TAGS'] - ansible.tags = tags - end + ansible.playbook = File.join(provisioning_path, 'dev.yml') + ansible.galaxy_role_file = File.join(provisioning_path, 'requirements.yml') + ansible.galaxy_roles_path = File.join(provisioning_path, 'vendor/roles') - ansible.extra_vars = {'vagrant_version' => Vagrant::VERSION} - if vars = ENV['ANSIBLE_VARS'] - extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }] - ansible.extra_vars.merge(extra_vars) - end + ansible.groups = { + 'web' => ['default'], + 'development' => ['default'] + } + + if tags = ENV['ANSIBLE_TAGS'] + ansible.tags = tags + end + + ansible.extra_vars = {'vagrant_version' => Vagrant::VERSION} + if vars = ENV['ANSIBLE_VARS'] + extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }] + ansible.extra_vars.merge(extra_vars) end end diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 622cf87e80..ce32ce7f2a 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -81,3 +81,9 @@ line: \1 myhostname regexp: ^(hosts\:((?!myhostname).)*)$ state: present + +- name: Generate SSH key for vagrant user + user: + name: vagrant + generate_ssh_key: yes + when: env == 'development' From f92e706e23f05ba2c79743e085af6d84403972c1 Mon Sep 17 00:00:00 2001 From: Kalen Johnson Date: Mon, 5 Dec 2016 14:52:22 -0800 Subject: [PATCH 4/4] CHANGELOG Update [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0e0d497d9..e7bc8982b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### HEAD +* Ansible-Local for Vagrant boxes on Windows ([#690](https://github.com/roots/trellis/pull/690)) * Nginx includes: Move templates dir, fix 'No such file' error ([#687](https://github.com/roots/trellis/pull/687)) * [BREAKING] Move shell scripts to bin/ directory ([#680](https://github.com/roots/trellis/pull/680)) * Add myhostname to nsswitch.conf to ensure resolvable hostname ([#686](https://github.com/roots/trellis/pull/686))