vagrant-salt 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/README.rst +154 -0
- data/Rakefile +2 -0
- data/example/.gitignore +1 -0
- data/example/Vagrantfile +23 -0
- data/example/salt/key/KEYPAIR_GOES_HERE +0 -0
- data/example/salt/minion.conf +220 -0
- data/example/salt/roots/pillar/top.sls +0 -0
- data/example/salt/roots/salt/top.sls +0 -0
- data/lib/vagrant-salt/provisioner.rb +141 -0
- data/lib/vagrant-salt.rb +4 -0
- data/lib/vagrant_init.rb +1 -0
- data/vagrant-salt.gemspec +19 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rst
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
==============
|
2
|
+
Salty Vagrant
|
3
|
+
==============
|
4
|
+
Provision `Vagrant`_ boxes using `Saltstack`_.
|
5
|
+
|
6
|
+
Discussion and questions happen in ``#salt`` on Freenode IRC. ping ``akoumjian``.
|
7
|
+
|
8
|
+
.. _`Vagrant`: http://www.vagrantup.com/
|
9
|
+
.. _`Saltstack`: http://saltstack.org/
|
10
|
+
.. _`Salt`: http://saltstack.org/
|
11
|
+
|
12
|
+
Introduction
|
13
|
+
============
|
14
|
+
|
15
|
+
Just like Chef or Puppet, Salt can be used as a provisioning tool.
|
16
|
+
`Salty Vagrant`_ lets you use your salt state tree and a your minion config
|
17
|
+
file to automatically build your dev environment the same way you use salt
|
18
|
+
to deploy for other environments.
|
19
|
+
|
20
|
+
.. _`Salty Vagrant`: https://github.com/akoumjian/salty-vagrant
|
21
|
+
|
22
|
+
There are two different ways to use `Salty Vagrant`_. The simplest way uses
|
23
|
+
the salt minion in a masterless configuration. With this option you distribute
|
24
|
+
your state tree along with your Vagrantfile and a dev minion config. The
|
25
|
+
minion will bootstrap itself and apply all necessary states.
|
26
|
+
|
27
|
+
The second method lets you specify a remote salt master, which assures that
|
28
|
+
the vagrant minion will always be able to fetch your most up to date state
|
29
|
+
tree. If you use a salt master, you will either need to manually accept
|
30
|
+
new vagrant minions on the master, or distribute preseeded keys along with
|
31
|
+
your vagrant files.
|
32
|
+
|
33
|
+
Masterless (Quick Start)
|
34
|
+
========================
|
35
|
+
|
36
|
+
1. Install `Vagrant`_
|
37
|
+
2. Install `Salty Vagrant`_ (``gem install vagrant-salt``)
|
38
|
+
3. Get the Ubuntu 12.04 base box: ``vagrant box add precise64 http://files.vagrantup.com/precise64.box``
|
39
|
+
4. Create/Update your ``Vagrantfile`` (Detailed in `Configuration`_)
|
40
|
+
5. Place your salt state tree in ``salt/roots/salt``
|
41
|
+
6. Place your minion config in ``salt/minion`` [#file_client]_
|
42
|
+
7. Run ``vagrant up`` and you should be good to go.
|
43
|
+
|
44
|
+
.. [#file_client] Make sure your minion config sets ``file_client: local`` for masterless
|
45
|
+
|
46
|
+
Using Remote Salt Master
|
47
|
+
========================
|
48
|
+
|
49
|
+
If you are already using `Salt`_ for deployment, you can use your existing
|
50
|
+
master to provision your vagrant boxes as well. You will need to do one of the
|
51
|
+
following:
|
52
|
+
|
53
|
+
#. Manually accept the vagrant's minion key after it boots. [#accept_key]_
|
54
|
+
#. Preseed the Vagrant box with minion keys pre-generated on the master
|
55
|
+
|
56
|
+
.. [#accept_key] This is not recommended. If your developers need to destroy and rebuild their VM, you will have to repeat the process.
|
57
|
+
|
58
|
+
Preseeding Vagrant Minion Keys
|
59
|
+
------------------------------
|
60
|
+
|
61
|
+
On the master, create the keypair and add the public key to the accepted minions
|
62
|
+
folder::
|
63
|
+
|
64
|
+
root@saltmaster# salt-key --gen-keys=[minion_id]
|
65
|
+
root@saltmaster# cp minion_id.pub /etc/salt/pki/minions/[minion_id]
|
66
|
+
|
67
|
+
Replace ``[minion_id]`` with the id you would like to assign the minion.
|
68
|
+
|
69
|
+
Next you want to bundle the key pair along with your Vagrantfile,
|
70
|
+
the salt_provisioner.rb, and your minion config. The directory should look
|
71
|
+
something like this::
|
72
|
+
|
73
|
+
myvagrant/
|
74
|
+
Vagrantfile
|
75
|
+
salt/
|
76
|
+
minion.conf
|
77
|
+
key/
|
78
|
+
minion.pem
|
79
|
+
minion.pub
|
80
|
+
|
81
|
+
You will need to determine your own secure method of transferring this
|
82
|
+
package. Leaking the minion's private key poses a security risk to your salt
|
83
|
+
network.
|
84
|
+
|
85
|
+
The are two required settings for your ``minion.conf`` file::
|
86
|
+
|
87
|
+
master: [master_fqdn]
|
88
|
+
id: [minion_id]
|
89
|
+
|
90
|
+
Make sure you use the same ``[minion_id]`` that you used on the master or
|
91
|
+
it will not match with the key.
|
92
|
+
|
93
|
+
Create/Update your ``Vagrantfile`` per the example provided in the `Configuration`_ section.
|
94
|
+
|
95
|
+
Finally, you should be able to run ``vagrant up`` and the salt should put your
|
96
|
+
vagrant minion in state.highstate.
|
97
|
+
|
98
|
+
|
99
|
+
Configuration
|
100
|
+
==============
|
101
|
+
|
102
|
+
Your ``Vagrantfile`` should look roughly like this::
|
103
|
+
|
104
|
+
Vagrant::Config.run do |config|
|
105
|
+
config.vm.box = "precise64"
|
106
|
+
## Use all the defaults:
|
107
|
+
config.vm.provision :salt do |salt|
|
108
|
+
salt.run_highstate = true
|
109
|
+
|
110
|
+
## Optional Settings:
|
111
|
+
# salt.minion_config = "salt/minion.conf"
|
112
|
+
|
113
|
+
## Only Use these with a masterless setup to
|
114
|
+
## load your state tree:
|
115
|
+
# salt.salt_file_root_path = "salt/roots/salt"
|
116
|
+
# salt.salt_pillar_root_path = "salt/roots/pillar"
|
117
|
+
|
118
|
+
## If you have a remote master setup, you can add
|
119
|
+
## your preseeded minion key
|
120
|
+
# salt.master = true
|
121
|
+
# salt.minion_key = "salt/key/testing.pem"
|
122
|
+
# salt.minion_pub = "salt/key/testing.pub"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
Inside of your Vagrantfile, there are a few parameters you can assign
|
127
|
+
depending on whether you are running masterless or with a remote master.
|
128
|
+
|
129
|
+
minion_config : "salt/minion.conf"
|
130
|
+
Path to your minion configuration file.
|
131
|
+
|
132
|
+
minion_key : false
|
133
|
+
String path to your minion key. Only useful with ``master=true``
|
134
|
+
|
135
|
+
minion_pub : false
|
136
|
+
String path to your minion public key. Only useful with ``master=true``
|
137
|
+
|
138
|
+
master : false
|
139
|
+
Boolean whether or not you want to use a remote master. If set to false,
|
140
|
+
make sure your minion config file has ``file_client: local`` set.
|
141
|
+
|
142
|
+
salt_file_root_path : "salt/roots/salt"
|
143
|
+
String path to your salt state tree. Only useful with ``master=false``.
|
144
|
+
|
145
|
+
salt_file_root_guest_path : "/srv/salt"
|
146
|
+
Path to share the file root state tree on the VM. Only use with ``master=false``.
|
147
|
+
|
148
|
+
salt_pillar_root_path : "salt/roots/pillar"
|
149
|
+
Path to share your pillar tree. Only useful with ``master=false``.
|
150
|
+
|
151
|
+
salt_pillar_root_guest_path : "/srv/pillar"
|
152
|
+
Path on VM where pillar tree will be shared. Only use with ``master=true``
|
153
|
+
|
154
|
+
|
data/Rakefile
ADDED
data/example/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.vagrant
|
data/example/Vagrantfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "../lib/vagrant-salt"
|
2
|
+
|
3
|
+
Vagrant::Config.run do |config|
|
4
|
+
config.vm.box = "precise64"
|
5
|
+
## Use all the defaults:
|
6
|
+
config.vm.provision :salt do |salt|
|
7
|
+
salt.run_highstate = true
|
8
|
+
|
9
|
+
## Optional Settings:
|
10
|
+
# salt.minion_config = "salt/minion.conf"
|
11
|
+
|
12
|
+
## Only Use these with a masterless setup to
|
13
|
+
## load your state tree:
|
14
|
+
# salt.salt_file_root_path = "salt/roots/salt"
|
15
|
+
# salt.salt_pillar_root_path = "salt/roots/pillar"
|
16
|
+
|
17
|
+
## If you have a remote master setup, you can add
|
18
|
+
## your preseeded minion key
|
19
|
+
# salt.master = true
|
20
|
+
# salt.minion_key = "salt/key/testing.pem"
|
21
|
+
# salt.minion_pub = "salt/key/testing.pub"
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# DO NOT MODIFY THIS FILE. Copy it to: /etc/salt/minion
|
2
|
+
##### Primary configuration settings #####
|
3
|
+
##########################################
|
4
|
+
# Set the location of the salt master server, if the master server cannot be
|
5
|
+
# resolved, then the minion will fail to start.
|
6
|
+
#master: salt
|
7
|
+
|
8
|
+
# Set the port used by the master reply and authentication server
|
9
|
+
#master_port: 4506
|
10
|
+
|
11
|
+
# The user to run salt
|
12
|
+
#user: root
|
13
|
+
|
14
|
+
# The root directory prepended to these options: pki_dir, cachedir, log_file.
|
15
|
+
#root_dir: /
|
16
|
+
|
17
|
+
# The directory to store the pki information in
|
18
|
+
#pki_dir: /etc/salt/pki
|
19
|
+
|
20
|
+
# Explicitly declare the id for this minion to use, if left commented the id
|
21
|
+
# will be the hostname as returned by the python call: socket.getfqdn()
|
22
|
+
# Since salt uses detached ids it is possible to run multiple minions on the
|
23
|
+
# same machine but with different ids, this can be useful for salt compute
|
24
|
+
# clusters.
|
25
|
+
#id: testing
|
26
|
+
|
27
|
+
# Append a domain to a hostname in the event that it does not exist. This is
|
28
|
+
# usefule for systems where socket.getfqdn() does not actually result in a
|
29
|
+
# FQDN (for instance, Solaris).
|
30
|
+
#append_domain:
|
31
|
+
|
32
|
+
# If the the connection to the server is interrupted, the minion will
|
33
|
+
# attempt to reconnect. sub_timeout allows you to control the rate
|
34
|
+
# of reconnection attempts (in seconds). To disable reconnects, set
|
35
|
+
# this value to 0.
|
36
|
+
#sub_timeout: 60
|
37
|
+
|
38
|
+
# Where cache data goes
|
39
|
+
#cachedir: /var/cache/salt
|
40
|
+
|
41
|
+
# The minion can locally cache the return data from jobs sent to it, this
|
42
|
+
# can be a good way to keep track of jobs the minion has executed
|
43
|
+
# (on the minion side). By default this feature is disabled, to enable
|
44
|
+
# set cache_jobs to True
|
45
|
+
#cache_jobs: False
|
46
|
+
|
47
|
+
# When waiting for a master to accept the minion's public key, salt will
|
48
|
+
# continuously attempt to reconnect until successful. This is the time, in
|
49
|
+
# seconds, between those reconnection attempts.
|
50
|
+
#acceptance_wait_time = 10
|
51
|
+
|
52
|
+
# When healing a dns_check is run, this is to make sure that the originally
|
53
|
+
# resolved dns has not changed, if this is something that does not happen in
|
54
|
+
# your environment then set this value to False.
|
55
|
+
#dns_check: True
|
56
|
+
|
57
|
+
|
58
|
+
##### Minion module management #####
|
59
|
+
##########################################
|
60
|
+
# Disable specific modules. This allows the admin to limit the level of
|
61
|
+
# access the master has to the minion
|
62
|
+
#disable_modules: [cmd,test]
|
63
|
+
#disable_returners: []
|
64
|
+
#
|
65
|
+
# Modules can be loaded from arbitrary paths. This enables the easy deployment
|
66
|
+
# of third party modules. Modules for returners and minions can be loaded.
|
67
|
+
# Specify a list of extra directories to search for minion modules and
|
68
|
+
# returners. These paths must be fully qualified!
|
69
|
+
#module_dirs: []
|
70
|
+
#returner_dirs: []
|
71
|
+
#states_dirs: []
|
72
|
+
#render_dirs: []
|
73
|
+
#
|
74
|
+
# A module provider can be statically overwritten or extended for the minion
|
75
|
+
# via the providers option, in this case the default module will be
|
76
|
+
# overwritten by the specified module. In this example the pkg module will
|
77
|
+
# be provided by the yumpkg5 module instead of the system default.
|
78
|
+
#
|
79
|
+
# providers:
|
80
|
+
# pkg: yumpkg5
|
81
|
+
#
|
82
|
+
# Enable Cython modules searching and loading. (Default: False)
|
83
|
+
#cython_enable: False
|
84
|
+
|
85
|
+
##### State Management Settings #####
|
86
|
+
###########################################
|
87
|
+
# The state management system executes all of the state templates on the minion
|
88
|
+
# to enable more granular control of system state management. The type of
|
89
|
+
# template and serialization used for state management needs to be configured
|
90
|
+
# on the minion, the default renderer is yaml_jinja. This is a yaml file
|
91
|
+
# rendered from a jinja template, the available options are:
|
92
|
+
# yaml_jinja
|
93
|
+
# yaml_mako
|
94
|
+
# json_jinja
|
95
|
+
# json_mako
|
96
|
+
#
|
97
|
+
#renderer: yaml_jinja
|
98
|
+
#
|
99
|
+
# state_verbose allows for the data returned from the minion to be more
|
100
|
+
# verbose. Normaly only states that fail or states that have changes are
|
101
|
+
# returned, but setting state_verbose to True will return all states that
|
102
|
+
# were checked
|
103
|
+
#state_verbose: False
|
104
|
+
#
|
105
|
+
# autoload_dynamic_modules Turns on automatic loading of modules found in the
|
106
|
+
# environments on the master. This is turned on by default, to turn of
|
107
|
+
# autoloading modules when states run set this value to False
|
108
|
+
#autoload_dynamic_modules: True
|
109
|
+
#
|
110
|
+
# clean_dynamic_modules keeps the dynamic modules on the minion in sync with
|
111
|
+
# the dynamic modules on the master, this means that if a dynamic module is
|
112
|
+
# not on the master it will be deleted from the minion. By default this is
|
113
|
+
# enabled and can be disabled by changing this value to False
|
114
|
+
#clean_dynamic_modules: True
|
115
|
+
#
|
116
|
+
# Normally the minion is not isolated to any single environment on the master
|
117
|
+
# when running states, but the environment can be isolated on the minion side
|
118
|
+
# by statically setting it. Remember that the recommended way to manage
|
119
|
+
# environments is to issolate via the top file.
|
120
|
+
#environment: None
|
121
|
+
#
|
122
|
+
# If using the local file directory, then the state top file name needs to be
|
123
|
+
# defined, by default this is top.sls.
|
124
|
+
#state_top: top.sls
|
125
|
+
|
126
|
+
##### File Directory Settings #####
|
127
|
+
##########################################
|
128
|
+
# The Salt Minion can redirect all file server operations to a local directory,
|
129
|
+
# this allows for the same state tree that is on the master to be used if
|
130
|
+
# coppied completely onto the minion. This is a literal copy of the settings on
|
131
|
+
# the master but used to reference a local directory on the minion.
|
132
|
+
|
133
|
+
# Set the file client, the client defaults to looking on the master server for
|
134
|
+
# files, but can be directed to look at the local file directory setting
|
135
|
+
# defined below by setting it to local.
|
136
|
+
#file_client: local
|
137
|
+
|
138
|
+
# The file directory works on environments passed to the minion, each environment
|
139
|
+
# can have multiple root directories, the subdirectories in the multiple file
|
140
|
+
# roots cannot match, otherwise the downloaded files will not be able to be
|
141
|
+
# reliably ensured. A base environment is required to house the top file.
|
142
|
+
# Example:
|
143
|
+
# file_roots:
|
144
|
+
# base:
|
145
|
+
# - /srv/salt/
|
146
|
+
# dev:
|
147
|
+
# - /srv/salt/dev/services
|
148
|
+
# - /srv/salt/dev/states
|
149
|
+
# prod:
|
150
|
+
# - /srv/salt/prod/services
|
151
|
+
# - /srv/salt/prod/states
|
152
|
+
#
|
153
|
+
# Default:
|
154
|
+
#file_roots:
|
155
|
+
# base:
|
156
|
+
# - /srv/salt
|
157
|
+
|
158
|
+
# The hash_type is the hash to use when discovering the hash of a file in
|
159
|
+
# the minion directory, the default is md5, but sha1, sha224, sha256, sha384
|
160
|
+
# and sha512 are also supported.
|
161
|
+
#hash_type: md5
|
162
|
+
|
163
|
+
# The Salt pillar is searched for locally if file_client is set to local. If
|
164
|
+
# this is the case, and pillar data is defined, then the pillar_roots need to
|
165
|
+
# also be configured on the minion:
|
166
|
+
#pillar_roots:
|
167
|
+
# base:
|
168
|
+
# - /srv/pillar
|
169
|
+
|
170
|
+
###### Security settings #####
|
171
|
+
###########################################
|
172
|
+
# Enable "open mode", this mode still maintains encryption, but turns off
|
173
|
+
# authentication, this is only intended for highly secure environments or for
|
174
|
+
# the situation where your keys end up in a bad state. If you run in open mode
|
175
|
+
# you do so at your own risk!
|
176
|
+
#open_mode: False
|
177
|
+
|
178
|
+
|
179
|
+
###### Thread settings #####
|
180
|
+
###########################################
|
181
|
+
# Disable multiprocessing support, by default when a minion receives a
|
182
|
+
# publication a new process is spawned and the command is executed therein.
|
183
|
+
#multiprocessing: True
|
184
|
+
|
185
|
+
###### Logging settings #####
|
186
|
+
###########################################
|
187
|
+
# The location of the minion log file
|
188
|
+
#log_file: /var/log/salt/minion
|
189
|
+
#
|
190
|
+
# The level of messages to send to the log file.
|
191
|
+
# One of 'info', 'quiet', 'critical', 'error', 'debug', 'warning'.
|
192
|
+
# Default: 'warning'
|
193
|
+
#log_level: warning
|
194
|
+
#
|
195
|
+
# Logger levels can be used to tweak specific loggers logging levels.
|
196
|
+
# For example, if you want to have the salt library at the 'warning' level,
|
197
|
+
# but you still wish to have 'salt.modules' at the 'debug' level:
|
198
|
+
# log_granular_levels: {
|
199
|
+
# 'salt': 'warning',
|
200
|
+
# 'salt.modules': 'debug'
|
201
|
+
# }
|
202
|
+
#
|
203
|
+
#log_granular_levels: {}
|
204
|
+
|
205
|
+
###### Module configuration #####
|
206
|
+
###########################################
|
207
|
+
# Salt allows for modules to be passed arbitrary configuration data, any data
|
208
|
+
# passed here in valid yaml format will be passed on to the salt minion modules
|
209
|
+
# for use. It is STRONGLY recommended that a naming convention be used in which
|
210
|
+
# the module name is followed by a . and then the value. Also, all top level
|
211
|
+
# data must be applied via the yaml dict construct, some examples:
|
212
|
+
#
|
213
|
+
# A simple value for the test module:
|
214
|
+
#test.foo: foo
|
215
|
+
#
|
216
|
+
# A list for the test module:
|
217
|
+
#test.bar: [baz,quo]
|
218
|
+
#
|
219
|
+
# A dict for the test module:
|
220
|
+
#test.baz: {spam: sausage, cheese: bread}
|
File without changes
|
File without changes
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module VagrantSalt
|
2
|
+
class Provisioner < Vagrant::Provisioners::Base
|
3
|
+
class Config < Vagrant::Config::Base
|
4
|
+
attr_accessor :minion_config
|
5
|
+
attr_accessor :minion_key
|
6
|
+
attr_accessor :minion_pub
|
7
|
+
attr_accessor :master
|
8
|
+
attr_accessor :run_highstate
|
9
|
+
attr_accessor :salt_file_root_path
|
10
|
+
attr_accessor :salt_file_root_guest_path
|
11
|
+
attr_accessor :salt_pillar_root_path
|
12
|
+
attr_accessor :salt_pillar_root_guest_path
|
13
|
+
|
14
|
+
def minion_config; @minion_config || "salt/minion.conf"; end
|
15
|
+
def minion_key; @minion_key || false; end
|
16
|
+
def minion_pub; @minion_pub || false; end
|
17
|
+
def master; @master || false; end
|
18
|
+
def run_highstate; @run_highstate || false; end
|
19
|
+
def salt_file_root_path; @salt_file_root_path || "salt/roots/salt"; end
|
20
|
+
def salt_file_root_guest_path; @salt_file_root_guest_path || "/srv/salt"; end
|
21
|
+
def salt_pillar_root_path; @salt_pillar_root_path || "salt/roots/pillar"; end
|
22
|
+
def salt_pillar_root_guest_path; @salt_pillar_root_guest_path || "/srv/pillar"; end
|
23
|
+
|
24
|
+
def expanded_path(root_path, rel_path)
|
25
|
+
Pathname.new(rel_path).expand_path(root_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.config_class
|
30
|
+
Config
|
31
|
+
end
|
32
|
+
|
33
|
+
def prepare
|
34
|
+
# Calculate the paths we're going to use based on the environment
|
35
|
+
@expanded_minion_config_path = config.expanded_path(env[:root_path], config.minion_config)
|
36
|
+
if !config.master
|
37
|
+
env[:ui].info "Adding state tree folders."
|
38
|
+
@expanded_salt_file_root_path = config.expanded_path(env[:root_path], config.salt_file_root_path)
|
39
|
+
@expanded_salt_pillar_root_path = config.expanded_path(env[:root_path], config.salt_pillar_root_path)
|
40
|
+
share_salt_file_root_path
|
41
|
+
share_salt_pillar_root_path
|
42
|
+
end
|
43
|
+
|
44
|
+
if config.minion_key
|
45
|
+
@expanded_minion_key_path = config.expanded_path(env[:root_path], config.minion_key)
|
46
|
+
@expanded_minion_pub_path = config.expanded_path(env[:root_path], config.minion_pub)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def share_salt_file_root_path
|
51
|
+
env[:ui].info "Sharing file root folder."
|
52
|
+
env[:vm].config.vm.share_folder("salt_file_root", config.salt_file_root_guest_path, @expanded_salt_file_root_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def share_salt_pillar_root_path
|
56
|
+
env[:ui].info "Sharing pillar root path."
|
57
|
+
env[:vm].config.vm.share_folder("salt_pillar_root", config.salt_pillar_root_guest_path, @expanded_salt_pillar_root_path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def salt_exists
|
61
|
+
env[:ui].info "Checking for salt binaries..."
|
62
|
+
if env[:vm].channel.test("which salt-call") and
|
63
|
+
env[:vm].channel.test("which salt-minion")
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
env[:ui].info "Salt binaries not found."
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_salt_repo
|
71
|
+
env[:ui].info "Adding Salt PPA."
|
72
|
+
env[:vm].channel.sudo("apt-get -q -y install python-software-properties")
|
73
|
+
env[:vm].channel.sudo("add-apt-repository -y ppa:saltstack/salt")
|
74
|
+
env[:vm].channel.sudo("apt-get -q -y update")
|
75
|
+
end
|
76
|
+
|
77
|
+
def install_salt_minion
|
78
|
+
env[:ui].info "Installing salt minion."
|
79
|
+
env[:vm].channel.sudo("apt-get -q -y install salt-minion")
|
80
|
+
end
|
81
|
+
|
82
|
+
def accept_minion_key
|
83
|
+
env[:ui].info "Accepting minion key."
|
84
|
+
env[:vm].channel.sudo("salt-key -A")
|
85
|
+
end
|
86
|
+
|
87
|
+
def call_highstate
|
88
|
+
if config.run_highstate
|
89
|
+
env[:ui].info "Calling state.highstate"
|
90
|
+
env[:vm].channel.sudo("salt-call saltutil.sync_all")
|
91
|
+
env[:vm].channel.sudo("salt-call state.highstate") do |type, data|
|
92
|
+
env[:ui].info(data)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
env[:ui].info "run_highstate set to false. Not running state.highstate."
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def upload_minion_config
|
100
|
+
env[:ui].info "Copying salt minion config to vm."
|
101
|
+
env[:vm].channel.upload(@expanded_minion_config_path.to_s, "/tmp/minion")
|
102
|
+
env[:vm].channel.sudo("mv /tmp/minion /etc/salt/minion")
|
103
|
+
end
|
104
|
+
|
105
|
+
def upload_minion_keys
|
106
|
+
env[:ui].info "Uploading minion key."
|
107
|
+
env[:vm].channel.upload(@expanded_minion_key_path.to_s, "/tmp/minion.pem")
|
108
|
+
env[:vm].channel.sudo("mv /tmp/minion.pem /etc/salt/pki/minion.pem")
|
109
|
+
env[:vm].channel.upload(@expanded_minion_pub_path.to_s, "/tmp/minion.pub")
|
110
|
+
env[:vm].channel.sudo("mv /tmp/minion.pub /etc/salt/pki/minion.pub")
|
111
|
+
end
|
112
|
+
|
113
|
+
def provision!
|
114
|
+
|
115
|
+
verify_shared_folders([config.salt_file_root_guest_path, config.salt_pillar_root_guest_path])
|
116
|
+
|
117
|
+
if !salt_exists
|
118
|
+
add_salt_repo
|
119
|
+
install_salt_minion
|
120
|
+
end
|
121
|
+
|
122
|
+
upload_minion_config
|
123
|
+
|
124
|
+
if config.minion_key
|
125
|
+
upload_minion_keys
|
126
|
+
end
|
127
|
+
|
128
|
+
call_highstate
|
129
|
+
end
|
130
|
+
|
131
|
+
def verify_shared_folders(folders)
|
132
|
+
folders.each do |folder|
|
133
|
+
# @logger.debug("Checking for shared folder: #{folder}")
|
134
|
+
env[:ui].info "Checking shared folder #{folder}"
|
135
|
+
if !env[:vm].channel.test("test -d #{folder}")
|
136
|
+
raise "Missing folder #{folder}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/lib/vagrant-salt.rb
ADDED
data/lib/vagrant_init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "vagrant-salt"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "vagrant-salt"
|
6
|
+
s.version = "0.1"
|
7
|
+
s.authors = ["Alec Koumjian", "Kiall Mac Innes"]
|
8
|
+
s.email = ["akoumjian@gmail.com", "kiall@managedit.ie"]
|
9
|
+
s.homepage = "https://github.com/akoumjian/salty-vagrant"
|
10
|
+
s.summary = %q{Vagrant Salt Stack provisioner plugin}
|
11
|
+
s.description = %q{Vagrant Salt Stack provisioner plugin}
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "vagrant"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-salt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alec Koumjian
|
13
|
+
- Kiall Mac Innes
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-07-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: vagrant
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Vagrant Salt Stack provisioner plugin
|
35
|
+
email:
|
36
|
+
- akoumjian@gmail.com
|
37
|
+
- kiall@managedit.ie
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.rst
|
48
|
+
- Rakefile
|
49
|
+
- example/.gitignore
|
50
|
+
- example/Vagrantfile
|
51
|
+
- example/salt/key/KEYPAIR_GOES_HERE
|
52
|
+
- example/salt/minion.conf
|
53
|
+
- example/salt/roots/pillar/top.sls
|
54
|
+
- example/salt/roots/salt/top.sls
|
55
|
+
- lib/vagrant-salt.rb
|
56
|
+
- lib/vagrant-salt/provisioner.rb
|
57
|
+
- lib/vagrant_init.rb
|
58
|
+
- vagrant-salt.gemspec
|
59
|
+
homepage: https://github.com/akoumjian/salty-vagrant
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.24
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Vagrant Salt Stack provisioner plugin
|
92
|
+
test_files: []
|
93
|
+
|