forked from infOpen/ansible-role-airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
87 lines (74 loc) · 3.16 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# Ansible version
ANSIBLE_DOWNLOAD_SOURCE = ENV['ANSIBLE_DOWNLOAD_SOURCE'] || "pip"
ANSIBLE_GIT_CHECKOUT = ENV['ANSIBLE_GIT_CHECKOUT'] || "HEAD"
ANSIBLE_GIT_REPOSITORY = ENV['ANSIBLE_GIT_REPOSITORY'] \
|| "https://github.com/ansible/ansible.git"
# Managed boxes for this role (should have all platform and version defined in
# meta/main.yml)
VMS = {
:trusty => {
:box => "ubuntu/trusty64"
}
}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
VMS.each_pair do |name, options|
config.vm.define name do |vm_config|
# Set proper box
vm_config.vm.box = options[:box]
# Need memory
vm_config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# Update system and install requirements
vm_config.vm.provision "shell" do |sh|
if ANSIBLE_DOWNLOAD_SOURCE == 'git'
sh.inline = "test -d /usr/local/src/ansible \
|| (sudo apt-get update \
&& sudo apt-get install python-dev python-pip \
curl git libffi-dev \
libssl-dev -y \
&& sudo pip install paramiko PyYAML Jinja2 \
httplib2 six pytest \
ansible-lint \
&& cd /usr/local/src \
&& sudo git clone #{ANSIBLE_GIT_REPOSITORY} \
&& cd ansible \
&& sudo git checkout #{ANSIBLE_GIT_CHECKOUT} \
&& sudo git submodule init \
&& sudo git submodule update \
&& sudo make install)"
else
sh.inline = "test -f /usr/local/bin/ansible \
|| (sudo apt-get update \
&& sudo apt-get install python-dev python-pip \
curl git libffi-dev \
libssl-dev -y \
&& sudo pip install paramiko PyYAML Jinja2 \
httplib2 six pytest ansible \
ansible-lint)"
end
end
# Use trigger plugin to set environment variable used by Ansible
# Needed with 2.0 home path change
vm_config.vm.provision "trigger" do |trigger|
trigger.fire do
ENV['ANSIBLE_ROLES_PATH'] = '../'
ENV['ANSIBLE_ROLE_NAME'] = File.basename(Dir.getwd)
end
end
# Run Ansible linter
vm_config.vm.provision "shell" do |sh|
sh.inline = "cd /vagrant && ansible-lint tasks/main.yml"
sh.privileged = false
end
# Run Ansible provisioning
vm_config.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test_vagrant.yml"
end
end
end
end