Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible-local for Vagrant and Windows #690

Merged
merged 7 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### HEAD
* Ansible-Local for Vagrant boxes on Windows ([#690](https://github.com/roots/trellis/pull/690))
* Install MariaDB via Ubuntu's official distro packages ([#693](https://github.com/roots/trellis/pull/693))
* Fix 404s by moving skip_cache conditions to server block ([#692](https://github.com/roots/trellis/pull/692))
* Nginx includes: Move templates dir, fix 'No such file' error ([#687](https://github.com/roots/trellis/pull/687))
Expand Down
49 changes: 24 additions & 25 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -87,29 +83,32 @@ Vagrant.configure('2') do |config|
end
end

if Vagrant::Util::Platform.windows?
config.vm.provision :shell do |sh|
sh.path = File.join(ANSIBLE_PATH, 'bin/windows.sh')
sh.args = [Vagrant::VERSION]
sh.keep_color = true
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.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 = {
'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
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.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

Expand Down
49 changes: 0 additions & 49 deletions bin/windows.sh

This file was deleted.

6 changes: 6 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'