forked from candlepin/candlepin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile
More file actions
112 lines (88 loc) · 3.7 KB
/
Copy pathVagrantfile
File metadata and controls
112 lines (88 loc) · 3.7 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
VAGRANTFILE_API_VERSION = "2"
ANSIBLE_TAGS_VAR = "ansible_tags"
ANSIBLE_SKIP_TAGS_VAR = "ansible_skip_tags"
ANSIBLE_VAR_PREFIX = "cp_"
ANSIBLE_VARS = {
:ansible_user => "vagrant",
:candlepin_user => "vagrant",
:candlepin_home => "/vagrant",
:cp_configure_postgresql => true,
:cp_configure_mariadb => true,
:cp_configure_user_env => true,
:cp_configure_debugging => true,
:cp_git_checkout => false,
:cp_deploy => false
}
# Commands that must always specify a target name
commands_requiring_target = %w[up halt resume ssh provision destroy]
cmd = ARGV[0]
if commands_requiring_target.include?(cmd)
# Any argument that is not a flag is considered a target machine
targets = ARGV.drop(1).reject { |arg| arg.start_with?("-") }
if targets.empty?
abort <<~MSG
'vagrant #{cmd}' requires a machine name (e.g. vagrant #{cmd} el9)
MSG
end
end
def configure_ansible_provisioning(vm_config)
vm_config.vm.provision "ansible" do |ansible|
# ansible.verbose = "vvv"
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/candlepin.yml"
ansible.galaxy_role_file = "ansible/requirements.yml"
# Impl note:
# At the time of writing, specifying the role path (as the default command does) prevents
# collections from being installed in some environments. Since we're now reliant on a number of
# non-core collections, it's critical that we pull both roles and collections at runtime.
# As a side effect, this will install roles and collections in the user's ~/.ansible directory,
# rather than in the candlepin/ansible/roles directory as it has in the past.
ansible.galaxy_command = "ansible-galaxy install -r %{role_file} --force"
ansible.extra_vars = ANSIBLE_VARS.clone
# Pass through ansible variables and tags from the environment variables
ENV.each do |key, value|
# Pass through anything starting with the "cp_" prefix
if key.downcase.start_with?(ANSIBLE_VAR_PREFIX)
ansible.extra_vars[key.downcase] = value
end
# Pass through ansible tags
if key.downcase == ANSIBLE_TAGS_VAR
ansible.tags = value
end
# Pass through ansible tags to skip
if key.downcase == ANSIBLE_SKIP_TAGS_VAR
ansible.skip_tags = value
end
end
end
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.synced_folder ".", "/vagrant", type: "sshfs", :owner => 'vagrant', :group => 'vagrant'
config.vm.host_name = "candlepin.example.com"
config.ssh.forward_agent = true
# Set up the hostmanager plugin to automatically configure host & guest hostnames
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = false
config.hostmanager.include_offline = true
end
config.vm.provider :libvirt do |provider|
provider.cpus = 4
provider.memory = 8192
provider.graphics_type = "spice"
provider.video_type = "qxl"
provider.machine_virtual_size = 100
end
config.vm.define("el9", autostart: false) do |vm_config|
vm_config.vm.box = "centos.cloud/centos9s"
vm_config.vm.box_url = "https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-Vagrant-9-latest.x86_64.vagrant-libvirt.box"
vm_config.vm.host_name = "candlepin-el9.example.com"
# Increase box disk size and resize partitions accordingly
vm_config.vm.disk :disk, size: "100GB", primary: true
vm_config.vm.provision "shell", inline: "echo '- +' | sfdisk --no-reread -N 1 /dev/vda && partprobe && resize2fs /dev/vda1"
# Update DNF CA certs
vm_config.vm.provision "shell", inline: "dnf update -y dnf ca-certificates"
configure_ansible_provisioning(vm_config)
end
end