vagrant-easyconfig 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitlab-ci.yml +9 -0
- data/Gemfile +11 -0
- data/README.md +197 -0
- data/lib/vagrant-easyconfig.rb +20 -0
- data/lib/vagrant-easyconfig/config.rb +181 -0
- data/lib/vagrant-easyconfig/config_template.rb +76 -0
- data/lib/vagrant-easyconfig/hash.rb +17 -0
- data/lib/vagrant-easyconfig/os.rb +20 -0
- data/lib/vagrant-easyconfig/plugins.rb +70 -0
- data/lib/vagrant-easyconfig/vm.rb +100 -0
- data/vagrant-easyconfig.gemspec +18 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93cd001163f24e4b4e7f64d7282eefae86052e54d847d0b58adf2a7aea879905
|
4
|
+
data.tar.gz: 8f5e829d0f0aed4c023f0b686202cdef6680715ef094d887d2fa0b9d7f5ee5ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 716ea8b74b8583fddb4dbb122bc8efa7452fa95d72d9267ccb4157e39a78a5257aeae273b902630c6e1352944fa8ad4c091d03c918b9e817e23cad117693c86e
|
7
|
+
data.tar.gz: d811b419f8aa84392eb67737ec96fed9cf82d91a899e3e02b2251919a0c21083441d966fa65e732dd67c58c7a9b94d4655110fd1b4bda986e904f8c578d520bf
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# EasyConfig Vagrant Plugin
|
2
|
+
|
3
|
+
This plugin is a collection of Ruby-files that can be placed inside a [Vagrant](https://www.vagrantup.com/) directory. When used it helps with configuring plugins, defining the VMs and provisioning with Ansible by providing a simple to configure YAML-file.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
`vagrant plugin install vagrant-easyconfig`
|
9
|
+
|
10
|
+
|
11
|
+
## YAML-File
|
12
|
+
|
13
|
+
The configuration file is hard-coded on purpose and when it is non-existent it will be created an can then be adapted therefrom. The file looks as follows
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
---
|
17
|
+
default:
|
18
|
+
vm:
|
19
|
+
gui: false
|
20
|
+
memory: 4096
|
21
|
+
cpus: 4
|
22
|
+
storage: 10GB
|
23
|
+
# list of boxes that may be used for this project
|
24
|
+
boxes:
|
25
|
+
ubuntu1804: ubuntu/bionic64
|
26
|
+
ubuntu: ubuntu/focal64
|
27
|
+
# key for the box that is used for this project
|
28
|
+
box: ubuntu
|
29
|
+
hosts:
|
30
|
+
# name of the host
|
31
|
+
example-host:
|
32
|
+
# if no ip is given it will be generated from net.ip
|
33
|
+
ip:
|
34
|
+
# groups used for ansible
|
35
|
+
groups:
|
36
|
+
# aliases are added to the /etc/hosts on the host and guest
|
37
|
+
aliases:
|
38
|
+
# override vm options per host
|
39
|
+
# vm:
|
40
|
+
# memory: 8192
|
41
|
+
plugins:
|
42
|
+
# automatically installs vbguest, hostmanager and disksize
|
43
|
+
auto_install: true
|
44
|
+
vbguest:
|
45
|
+
# turn off auto_update of vbguest
|
46
|
+
auto_update: true
|
47
|
+
linked_clones: true
|
48
|
+
net:
|
49
|
+
# ip to auto generate IPs from
|
50
|
+
# incrementing by 1 for every host
|
51
|
+
ip: 192.168.100.100
|
52
|
+
private_nic_type: 82540EM
|
53
|
+
network_type: private_network
|
54
|
+
ansible:
|
55
|
+
# whether to use ansible_local or ansible provisioner
|
56
|
+
local: true
|
57
|
+
# whether to install ansible with guest OS or pip
|
58
|
+
pip: false
|
59
|
+
# where the ansible project is located
|
60
|
+
playbook_path:
|
61
|
+
# where the playbook is located inside the ansible project
|
62
|
+
playbook:
|
63
|
+
# when used passes the extra_vars to ansible
|
64
|
+
extra_vars:
|
65
|
+
# when used only tasks with these tags are run
|
66
|
+
tags:
|
67
|
+
# when used all tasks except for one with these tags are run
|
68
|
+
skip_tags:
|
69
|
+
# toggle verbose logging for ansible
|
70
|
+
verbose: false
|
71
|
+
# will be disable on unix systems
|
72
|
+
windows:
|
73
|
+
ssh:
|
74
|
+
# specify ssh-key location
|
75
|
+
key:
|
76
|
+
# override for current host
|
77
|
+
# by specifying the hostname of the current machine
|
78
|
+
# all settings under this key are overriding the default section
|
79
|
+
# example-host:
|
80
|
+
# vm:
|
81
|
+
# memory: 8192
|
82
|
+
# hosts:
|
83
|
+
# example-host:
|
84
|
+
# vm:
|
85
|
+
# memory: 16384
|
86
|
+
```
|
87
|
+
|
88
|
+
### Overriding
|
89
|
+
|
90
|
+
There are two sections that can be utilized for overriding default values.
|
91
|
+
|
92
|
+
#### Overriding per Host
|
93
|
+
|
94
|
+
Supposing a project is used on different hosts which in turn have a different set of resources available (which is expected and does not impair the functionality of the project for the intended purposes). Then it would be helpful to dedicate a specific amount of resources to the project (VM) depending on that host. For this reason and others it is possible to override all of the settings inside the `default` block by custom values depending on the host it is used in.
|
95
|
+
|
96
|
+
Therefore one has to specify another block below the `default` block, the key being the `hostname` of the host. When the host's `hostname` is **example-host** the key should be **example-host**. An example is given in the code above from line 61-68.
|
97
|
+
|
98
|
+
---
|
99
|
+
|
100
|
+
This may also benefit if for example the Vagrant version is different and in one it is not possible to use the `pip-installation` of `Ansible`. Or some provisioning should be skipped, then it can be set in the `host`-specific section with `Ansible`-tags.
|
101
|
+
|
102
|
+
#### Overriding per Guest
|
103
|
+
|
104
|
+
Sometimes one expects all the Guest-VMs to have the same specifications, e.g. when creating a Kubernetes-Cluster. However, if the setup requires different Hosts, i.e. database-hosts, master- and slaves, control- and production-machines, then the Guest-machines may need different specs. Therefore it is possible to define a `vm`-section inside the `host`-section. This then overrides the default values of the `vm`-section. An example is given in the code above in line 23-25.
|
105
|
+
|
106
|
+
### Boxes
|
107
|
+
|
108
|
+
It is possible to specify a list of boxes in the `boxes`-section. The `box`-section then is set with the key from the `boxes`-section. That makes sense, when the project should support multiple platforms and those should be persisted.
|
109
|
+
|
110
|
+
### IPs
|
111
|
+
|
112
|
+
The section `net.ip` specifies the base IP-address. When no IPs are specified inside the `host`-sections this one is used and incremented by one for every guest, and then assigning it.
|
113
|
+
|
114
|
+
This can be overridden by specifying an IP-address directly in the `host`-section as can be seen in line 36.
|
115
|
+
|
116
|
+
### Groups
|
117
|
+
|
118
|
+
Groups refer to `Ansible`-groups. This is a simple way to group Guests together. Only single strings or a simple list of strings is allowed, so no complex nested groups can be created like this.
|
119
|
+
|
120
|
+
### Aliases
|
121
|
+
|
122
|
+
A host may need aliases that should be specified to make it reachable through different `hostnames`. Rancher's UI (Website of the Kubernetes-Product Rancher), can only be access through a root path of a URL, as otherwise assets are not reachable. Therefore this product requires the host to be reachable via two `hostnames`. One for the UI and one for reaching the Kubernetes-services themselves.
|
123
|
+
|
124
|
+
the `hosts.*.aliases`-section is a string-list and those will be added to the host's and guest's `/etc/hosts`-files.
|
125
|
+
|
126
|
+
### Plugins
|
127
|
+
|
128
|
+
The `plugins.auto_install`-section allows toggling on and off the auto installation of the plugins `vagrant-vbguest`, `vagrant-hostmanager` and `vagrant-disksize`.
|
129
|
+
|
130
|
+
The `plugins.vbguest.auto_update`-section allows toggling on and off the auto installation of the most recent version of the `VirtualBox Guest Extensions`.
|
131
|
+
|
132
|
+
### Ansible
|
133
|
+
|
134
|
+
| section | default | description |
|
135
|
+
| --------------- | -------------- | ------------------------------------------------------------ |
|
136
|
+
| `local` | `true` | Use the `ansible_local` provisioner. Meaning the `Ansible` project is directly invoked on the Guest-machine by specifying the target to be `localhost` and the `connection` being `local`.<br />Otherwise use the `ansible` provisioner, invoking `Ansible` from the host against the Guest-machine. |
|
137
|
+
| `pip` | `false` | Use the `pip` to install `Ansible` on the Guest-machine, when not available and using `local=true`.<br />Otherwise use the systems package manager to install `Ansible`, i.e. aptitude, yum, dnf... |
|
138
|
+
| `playbook_path` | `ansible` | The location of the `Ansible`-project. If nothing is specified the directory `<vagrant-directory>/ansible` is assumed. |
|
139
|
+
| `playbook` | `playbook.yml` | The location of the `Playbook`-file. If nothing is specified `playbook.yml` is assumed. |
|
140
|
+
| `extra_vars` | `nil` | If used passes the extra_vars to `Ansible`. |
|
141
|
+
| `tags` | `nil` | If specified only tasks/roles with these tags are run. |
|
142
|
+
| `skip_tags` | `nil` | If specified tasks/roles with these tags are skipped. |
|
143
|
+
| `verbose` | `false` | Make output more verbose. |
|
144
|
+
|
145
|
+
## Usage
|
146
|
+
|
147
|
+
A classic usage of the plugin looks as follows:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
# -*- mode: ruby -*-
|
151
|
+
# vi: set ft=ruby :
|
152
|
+
|
153
|
+
EasyConfig::Config.load("config.yaml")
|
154
|
+
EasyConfig::Config.print()
|
155
|
+
|
156
|
+
Vagrant.configure("2") do |config|
|
157
|
+
EasyConfig::Plugins.configure(config)
|
158
|
+
EasyConfig::VM.each(config) do |host|
|
159
|
+
# do something except defining
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
```
|
164
|
+
|
165
|
+
### Load the config.yaml
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
EasyConfig::Config.load("config.yaml")
|
169
|
+
```
|
170
|
+
|
171
|
+
In the previous major section, the `config.yaml` was described. This one has to be loaded. If the file does not exist, a `config.yaml.template` is automatically created at the specified location, which can then be moved or copied and adapted.
|
172
|
+
|
173
|
+
### Always see the configuration
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
EasyConfig::Config.print()
|
177
|
+
```
|
178
|
+
|
179
|
+
This will just print out the configuration. By putting this directly after loading it is shown with every `vagrant` command executed. It could also be put in the trigger sections if needed.
|
180
|
+
|
181
|
+
### Plugin-Configuration
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
EasyConfig::Plugins.configure(config)
|
185
|
+
```
|
186
|
+
|
187
|
+
Plugins mostly need the `config` to be configured. Thus the `config` has to be passed to the `EasyConfig::Plugins` module, for it to be able to configure the plugins on the host-level, i.e. for each guest the same configuration.
|
188
|
+
|
189
|
+
### Define the VMs
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
EasyConfig::VM.each(config) do |host|
|
193
|
+
# do something except defining
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
This is enough to define all the VMs specified inside the `config.yaml` with the `Ansible`-provisioner. It is still possible to add further configuration code inside the block of the `each`-function which gets the `host`-configuration passed.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'vagrant'
|
6
|
+
rescue LoadError
|
7
|
+
raise 'The EasyConfig Vagrant Plugin must be run within Vagrant'
|
8
|
+
end
|
9
|
+
|
10
|
+
module EasyConfig
|
11
|
+
class Plugin < Vagrant.plugin('2')
|
12
|
+
name 'EasyConfig'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require_relative "vagrant-easyconfig/hash.rb"
|
17
|
+
require_relative "vagrant-easyconfig/os.rb"
|
18
|
+
require_relative "vagrant-easyconfig/plugins.rb"
|
19
|
+
require_relative "vagrant-easyconfig/config.rb"
|
20
|
+
require_relative "vagrant-easyconfig/vm.rb"
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
require_relative "config_template.rb"
|
5
|
+
require_relative "os.rb"
|
6
|
+
require "yaml"
|
7
|
+
require "ipaddr"
|
8
|
+
|
9
|
+
module EasyConfig
|
10
|
+
module Config
|
11
|
+
extend self
|
12
|
+
|
13
|
+
@@config = {}
|
14
|
+
|
15
|
+
def self.load(path)
|
16
|
+
config_path = File.expand_path(path, Dir.pwd)
|
17
|
+
vagrantfile_path = File.expand_path('Vagrantfile', Dir.pwd)
|
18
|
+
unless File.exist? vagrantfile_path
|
19
|
+
config_path = File.expand_path(path, File.dirname(File.dirname(File.dirname(__FILE__))))
|
20
|
+
end
|
21
|
+
unless File.exist? config_path
|
22
|
+
File.write("#{config_path}.template", @@config_template)
|
23
|
+
abort <<~EOL
|
24
|
+
Easyconfig:Config.load: Cannot load file [#{config_path}]
|
25
|
+
Easyconfig:Config.load: Create template [#{config_path}.template]
|
26
|
+
Easyconfig:Config.load: Copy the template to [#{config_path}] and adapt
|
27
|
+
EOL
|
28
|
+
end
|
29
|
+
|
30
|
+
self.merge_template config_path
|
31
|
+
self.merge_default
|
32
|
+
self.set_hostnames
|
33
|
+
self.set_boxes
|
34
|
+
self.auto_install_plugins
|
35
|
+
self.initialize_ansible
|
36
|
+
|
37
|
+
unless OS.windows?
|
38
|
+
@@config.delete("windows")
|
39
|
+
end
|
40
|
+
|
41
|
+
self.post_initialize
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get(*args)
|
46
|
+
if @@config == nil
|
47
|
+
abort "Easyconfig:Config.get: load config first with [Config.load(path)]"
|
48
|
+
end
|
49
|
+
if args.length == 0
|
50
|
+
return Marshal.load(Marshal.dump(@@config))
|
51
|
+
end
|
52
|
+
return Marshal.load(Marshal.dump(@@config.dig(*args)))
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.print
|
56
|
+
if @@config == nil
|
57
|
+
abort "Easyconfig:Config.print: load config first with [Config.load(path)]"
|
58
|
+
end
|
59
|
+
puts @@config.to_yaml
|
60
|
+
puts "---\n\n"
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def self.merge_template(config_path)
|
67
|
+
template = YAML.load(@@config_template)
|
68
|
+
# remove default host as it needs to be overridden
|
69
|
+
template["default"]["hosts"] = {}
|
70
|
+
file = YAML.load_file(config_path)
|
71
|
+
@@config = template.deep_merge!(file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.merge_default
|
75
|
+
hostname = "#{`hostname`[0..-2]}"
|
76
|
+
default = @@config.fetch("default")
|
77
|
+
key = [hostname, hostname.downcase].detect {|key| @@config.key?(key)}
|
78
|
+
if key and (specific = @@config.fetch(key)) != nil
|
79
|
+
default.deep_merge!(specific)
|
80
|
+
end
|
81
|
+
@@config = default
|
82
|
+
|
83
|
+
vm = @@config.fetch("vm")
|
84
|
+
ip = @@config.dig("net", "ip")
|
85
|
+
hosts = @@config.fetch("hosts")
|
86
|
+
hosts.each_with_index do |item, index|
|
87
|
+
hostname = item[0]
|
88
|
+
unless item[1]
|
89
|
+
hosts[hostname] = {}
|
90
|
+
end
|
91
|
+
host = hosts[hostname]
|
92
|
+
# create temporary copy of host
|
93
|
+
temp = Marshal.load(Marshal.dump(host))
|
94
|
+
# override host with default values
|
95
|
+
host["vm"] = host.fetch("vm", {}).deep_merge!(vm)
|
96
|
+
# re-override host with previous values from temp
|
97
|
+
host["vm"].deep_merge!(temp.fetch("vm", {}))
|
98
|
+
|
99
|
+
if host.fetch("ip","") == nil or host.fetch("ip",nil) == nil
|
100
|
+
host["ip"] = IPAddr.new(IPAddr.new(ip, Socket::AF_INET).to_i + index, Socket::AF_INET).to_s
|
101
|
+
end
|
102
|
+
end
|
103
|
+
@@config.delete("vm")
|
104
|
+
@@config["net"].delete("ip")
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.set_hostnames
|
108
|
+
@@config.fetch("hosts").keys.each do |guestname|
|
109
|
+
|
110
|
+
if @@config.dig("hosts", guestname).key?("aliases")
|
111
|
+
aliases = @@config.dig("hosts", guestname, "aliases")
|
112
|
+
if aliases.kind_of?(Array) && aliases.length > 0
|
113
|
+
aliases = aliases.map {|a| a = "#{`hostname`[0..-2].downcase}-#{a}"}
|
114
|
+
@@config["hosts"][guestname]["aliases"] = aliases
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
@@config["hosts"]["#{`hostname`[0..-2]}-#{guestname}".downcase] = @@config["hosts"][guestname]
|
119
|
+
@@config["hosts"].delete(guestname)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.set_boxes
|
124
|
+
# box = @@config.dig("vm","boxes").fetch(@@config.dig("vm","box"))
|
125
|
+
# @@config["vm"]["box"] = box
|
126
|
+
# @@config["vm"].delete("boxes")
|
127
|
+
|
128
|
+
@@config.fetch("hosts").each do |hostname, host|
|
129
|
+
box = host.dig("vm", "boxes").fetch(host.dig("vm","box"))
|
130
|
+
host["vm"]["box"] = box
|
131
|
+
host["vm"].delete("boxes")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.auto_install_plugins
|
136
|
+
if @@config.dig("plugins","auto_install")
|
137
|
+
required_plugins = %w( vagrant-hostmanager vagrant-vbguest vagrant-disksize )
|
138
|
+
_retry = false
|
139
|
+
required_plugins.each do |plugin|
|
140
|
+
unless Vagrant.has_plugin? plugin
|
141
|
+
system "vagrant plugin install #{plugin}"
|
142
|
+
_retry=true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if (_retry)
|
147
|
+
exec "vagrant " + ARGV.join(' ')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.initialize_ansible
|
153
|
+
project_path = @@config.dig("ansible","project_path")
|
154
|
+
if project_path == nil or project_path == ""
|
155
|
+
project_path = "ansible"
|
156
|
+
end
|
157
|
+
if @@config.dig("ansible","local")
|
158
|
+
project_path = "/vagrant/#{ project_path }".gsub(%r{/+},'/')
|
159
|
+
end
|
160
|
+
@@config["ansible"]["project_path"] = project_path
|
161
|
+
|
162
|
+
playbook = @@config.dig("ansible","playbook")
|
163
|
+
if playbook == nil or playbook == ""
|
164
|
+
playbook = "playbook.yml"
|
165
|
+
end
|
166
|
+
@@config["ansible"]["playbook"] = playbook.gsub(%r{/+},'/')
|
167
|
+
end
|
168
|
+
def self.post_initialize
|
169
|
+
if OS.windows?
|
170
|
+
unless @@config.dig("windows","ssh","key") != nil and @@config.dig("windows","ssh","key") != ""
|
171
|
+
abort <<~EOL
|
172
|
+
Easyconfig:Config.initialize_ansible: On Windows please add [windows.ssh.key] to config.yaml
|
173
|
+
Easyconfig:Config.initialize_ansible: and pass the absolute path to your ssh key file
|
174
|
+
EOL
|
175
|
+
end
|
176
|
+
config.ssh.insert_key = false
|
177
|
+
config.ssh.private_key_path = [@@config.dig("windows","ssh","key")]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module EasyConfig
|
2
|
+
module Config
|
3
|
+
@@config_template = <<-EOL.strip
|
4
|
+
---
|
5
|
+
default:
|
6
|
+
vm:
|
7
|
+
gui: false
|
8
|
+
memory: 4096
|
9
|
+
cpus: 4
|
10
|
+
storage: 10GB
|
11
|
+
# list of boxes that may be used for this project
|
12
|
+
boxes:
|
13
|
+
ubuntu1804: ubuntu/bionic64
|
14
|
+
ubuntu: ubuntu/focal64
|
15
|
+
# key for the box that is used for this project
|
16
|
+
box: ubuntu
|
17
|
+
hosts:
|
18
|
+
# name of the host
|
19
|
+
example-host:
|
20
|
+
# if no ip is given it will be generated from net.ip
|
21
|
+
ip:
|
22
|
+
# groups used for ansible
|
23
|
+
groups:
|
24
|
+
# aliases are added to the /etc/hosts on the host and guest
|
25
|
+
aliases:
|
26
|
+
# override vm options per host
|
27
|
+
# vm:
|
28
|
+
# memory: 8192
|
29
|
+
plugins:
|
30
|
+
# automatically installs vbguest, hostmanager and disksize
|
31
|
+
auto_install: true
|
32
|
+
vbguest:
|
33
|
+
# turn off auto_update of vbguest
|
34
|
+
auto_update: true
|
35
|
+
linked_clones: true
|
36
|
+
net:
|
37
|
+
# ip to auto generate IPs from
|
38
|
+
# incrementing by 1 for every host
|
39
|
+
ip: 192.168.100.100
|
40
|
+
private_nic_type: 82540EM
|
41
|
+
network_type: private_network
|
42
|
+
ansible:
|
43
|
+
# whether to use ansible_local or ansible provisioner
|
44
|
+
local: true
|
45
|
+
# whether to install ansible with guest OS or pip
|
46
|
+
pip: false
|
47
|
+
# where the ansible project is located
|
48
|
+
project_path:
|
49
|
+
# where the playbook is located inside the ansible project
|
50
|
+
playbook:
|
51
|
+
# when used passes the extra_vars to ansible
|
52
|
+
extra_vars:
|
53
|
+
# when used only tasks with these tags are run
|
54
|
+
tags:
|
55
|
+
# when used all tasks except for one with these tags are run
|
56
|
+
skip_tags:
|
57
|
+
# toggle verbose logging for ansible
|
58
|
+
verbose: false
|
59
|
+
# will be disable on unix systems
|
60
|
+
windows:
|
61
|
+
ssh:
|
62
|
+
# specify ssh-key location
|
63
|
+
key:
|
64
|
+
# override for current host
|
65
|
+
# by specifying the hostname of the current machine
|
66
|
+
# all settings under this key are overriding the default section
|
67
|
+
#{`hostname`[0..-2].downcase}:
|
68
|
+
# vm:
|
69
|
+
# memory: 8192
|
70
|
+
# hosts:
|
71
|
+
# example-host:
|
72
|
+
# vm:
|
73
|
+
# memory: 16384
|
74
|
+
EOL
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
class ::Hash
|
5
|
+
def deep_merge(second)
|
6
|
+
merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
|
7
|
+
merge(second.to_h, &merger)
|
8
|
+
end
|
9
|
+
def deep_merge!(second)
|
10
|
+
merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
|
11
|
+
merge!(second.to_h, &merger)
|
12
|
+
end
|
13
|
+
def deep_update!(second)
|
14
|
+
merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2.select { |k| v1.keys.include? k }, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
|
15
|
+
merge!(second.to_h.select { |k| keys.include? k }, &merger)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
module OS
|
5
|
+
def OS.windows?
|
6
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def OS.mac?
|
10
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def OS.unix?
|
14
|
+
!OS.windows?
|
15
|
+
end
|
16
|
+
|
17
|
+
def OS.linux?
|
18
|
+
OS.unix? and not OS.mac?
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
module EasyConfig
|
5
|
+
module Plugins
|
6
|
+
def self.configure(config)
|
7
|
+
self.configure_hostmanager(config)
|
8
|
+
self.configure_vbguest(config)
|
9
|
+
return nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure_hostmanager(config)
|
13
|
+
if Vagrant.has_plugin?('vagrant-hostmanager')
|
14
|
+
config.hostmanager.enabled = true
|
15
|
+
config.hostmanager.manage_host = true
|
16
|
+
config.hostmanager.manage_guest = true
|
17
|
+
config.hostmanager.ignore_private_ip = false
|
18
|
+
config.hostmanager.include_offline = true
|
19
|
+
else
|
20
|
+
puts <<~EOL
|
21
|
+
Easyconfig:Plugins.configure_hostmanager: no hosts plugin installed, thus no aliases are added to the /etc/hosts file
|
22
|
+
Easyconfig:Plugins.configure_hostmanager: plugin examples: vagrant-hostmanager
|
23
|
+
EOL
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure_vbguest(config)
|
29
|
+
if Vagrant.has_plugin?("vagrant-vbguest")
|
30
|
+
auto_update = Config.get("plugins","vbguest","auto_update")
|
31
|
+
config.vbguest.auto_update = auto_update != nil ? auto_update : true
|
32
|
+
if OS.unix?
|
33
|
+
config.vm.synced_folder ".", "/vagrant", disabled: false
|
34
|
+
else
|
35
|
+
config.vm.synced_folder ".", "/vagrant", disabled: false, mount_options: ["dmode=0755,fmode=0644"]
|
36
|
+
end
|
37
|
+
else
|
38
|
+
puts <<~EOL
|
39
|
+
Easyconfig:Plugins.configure_vbguest: no vagrant-vbguest plugin installed, thus no autoupdates and synced folders are working
|
40
|
+
Easyconfig:Plugins.configure_vbguest: install with: vagrant plugin install vagrant-vbguest
|
41
|
+
EOL
|
42
|
+
end
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.configure_disksize(config)
|
47
|
+
if Vagrant.has_plugin?("vagrant-disksize")
|
48
|
+
config.disksize.size = Config.get("hosts", config.vm.hostname, "vm","storage")
|
49
|
+
else
|
50
|
+
puts <<~EOL
|
51
|
+
Easyconfig:Plugins.configure_disksize: no disksize plugin installed, thus storage is not set correctly to #{ vm.fetch("storage") }
|
52
|
+
Easyconfig:Plugins.configure_disksize: vagrant plugin install vagrant-disksize
|
53
|
+
EOL
|
54
|
+
end
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.add_aliases(config)
|
59
|
+
if Vagrant.has_plugin?('vagrant-hostmanager')
|
60
|
+
if Config.get("hosts", config.vm.hostname).key?("aliases")
|
61
|
+
aliases = Config.get("hosts", config.vm.hostname,"aliases")
|
62
|
+
if aliases.kind_of?(Array) && aliases.length > 0
|
63
|
+
config.hostmanager.aliases = aliases
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
module EasyConfig
|
5
|
+
module VM
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def self.each(config, &block)
|
9
|
+
hostnames = Config.get("hosts").keys
|
10
|
+
Config.get("hosts").each_with_index do |item, index|
|
11
|
+
hostname = item[0]
|
12
|
+
host_config = item[1]
|
13
|
+
|
14
|
+
config.vm.define hostname do |host|
|
15
|
+
self.define(host, hostname, host_config, index == hostnames.size-1)
|
16
|
+
|
17
|
+
block.call(host)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.define(config, hostname, host, provision)
|
25
|
+
ip = host.fetch("ip")
|
26
|
+
type = Config.get("net","network_type")
|
27
|
+
nic_type = Config.get("net","private_nic_type")
|
28
|
+
config.vm.network type, ip: ip, nic_type: nic_type
|
29
|
+
|
30
|
+
config.vm.box = host.dig("vm","box")
|
31
|
+
|
32
|
+
config.vm.hostname = hostname
|
33
|
+
|
34
|
+
config.vm.provider :virtualbox do |vb|
|
35
|
+
|
36
|
+
vb.gui = host.dig("vm","gui")
|
37
|
+
vb.cpus = host.dig("vm","cpus")
|
38
|
+
vb.memory = host.dig("vm","memory")
|
39
|
+
vb.name = hostname
|
40
|
+
# vb.default_nic_type = nic_type
|
41
|
+
vb.linked_clone = true if Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.8.0') and Config.get("linked_clones")
|
42
|
+
vb.customize ["modifyvm", :id, "--nictype1", nic_type]
|
43
|
+
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
|
44
|
+
|
45
|
+
# workaround for Ubuntu 20.04
|
46
|
+
if ["ubuntu/focal", "Easyconfig/ubuntu-desktop-focal-20.04-lts"].include? host.dig("vm","box")
|
47
|
+
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
|
48
|
+
vb.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if Config.get("ansible","local") or provision
|
53
|
+
playbook_file = File.expand_path(
|
54
|
+
Config.get("ansible","playbook"),
|
55
|
+
Config.get("ansible","project_path")
|
56
|
+
).gsub(%r{/vagrant/},'')
|
57
|
+
if File.exist? playbook_file
|
58
|
+
config.vm.provision "ansible#{ "_local" if Config.get("ansible","local") }" do |ansible|
|
59
|
+
if Config.get("ansible","local") and Config.get("ansible","pip")
|
60
|
+
ansible.install_mode = "pip"
|
61
|
+
end
|
62
|
+
config_path = "#{Config.get("ansible","project_path")}/ansible.cfg"
|
63
|
+
if File.exist?(config_path)
|
64
|
+
ansible.config_file = "#{Config.get("ansible","project_path")}/ansible.cfg"
|
65
|
+
end
|
66
|
+
ansible.playbook = Config.get("ansible","playbook")
|
67
|
+
ansible.provisioning_path = Config.get("ansible","project_path")
|
68
|
+
ansible.extra_vars = Config.get("ansible","extra_vars")
|
69
|
+
ansible.verbose = Config.get("ansible","verbose")
|
70
|
+
ansible.tags = Config.get("ansible","tags")
|
71
|
+
ansible.skip_tags = Config.get("ansible","skip_tags")
|
72
|
+
ansible.compatibility_mode = "2.0"
|
73
|
+
|
74
|
+
groups = {}
|
75
|
+
Config.get("hosts").each do |hostname, host|
|
76
|
+
if host.key?("groups") and host.fetch("groups") != nil
|
77
|
+
host_groups = host.fetch("groups")
|
78
|
+
unless host_groups.kind_of?(Array)
|
79
|
+
host_groups = [host_groups]
|
80
|
+
end
|
81
|
+
host_groups.each do |group|
|
82
|
+
unless groups.key?(group)
|
83
|
+
groups[group] = []
|
84
|
+
end
|
85
|
+
groups[group] << hostname
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
ansible.groups = groups
|
90
|
+
end
|
91
|
+
else
|
92
|
+
puts "Easyconfig:VM.define: no ansible playbook available at [#{playbook_file}]"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
Plugins.configure_disksize(config)
|
96
|
+
Plugins.add_aliases(config)
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "vagrant-easyconfig"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.license = "MIT"
|
5
|
+
s.authors = ["Daniel Satanik", "Benjamin Akhras"]
|
6
|
+
s.email = ["daniel@satanik.at"]
|
7
|
+
s.homepage = "https://gitlab.com/dessecated-unicorn/vagrant-easyconfig"
|
8
|
+
s.summary = "Vagrant plugin easy yaml configs"
|
9
|
+
s.description = "Vagrant plugin for easy VMs, provisioning and Ansible configuration."
|
10
|
+
|
11
|
+
all_files = `git ls-files`.split("\n")
|
12
|
+
s.files = all_files
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
|
15
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
16
|
+
s.extra_rdoc_files = %w(README.md)
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-easyconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Satanik
|
8
|
+
- Benjamin Akhras
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Vagrant plugin for easy VMs, provisioning and Ansible configuration.
|
15
|
+
email:
|
16
|
+
- daniel@satanik.at
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- ".gitlab-ci.yml"
|
24
|
+
- Gemfile
|
25
|
+
- README.md
|
26
|
+
- lib/vagrant-easyconfig.rb
|
27
|
+
- lib/vagrant-easyconfig/config.rb
|
28
|
+
- lib/vagrant-easyconfig/config_template.rb
|
29
|
+
- lib/vagrant-easyconfig/hash.rb
|
30
|
+
- lib/vagrant-easyconfig/os.rb
|
31
|
+
- lib/vagrant-easyconfig/plugins.rb
|
32
|
+
- lib/vagrant-easyconfig/vm.rb
|
33
|
+
- vagrant-easyconfig.gemspec
|
34
|
+
homepage: https://gitlab.com/dessecated-unicorn/vagrant-easyconfig
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- "--charset=UTF-8"
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.2.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Vagrant plugin easy yaml configs
|
58
|
+
test_files: []
|