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

Use salt provisioner. #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.pem
*.pub
base/*
.vagrant
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
all: keys base up

keys:
$(MAKE) -C keys

base:
mkdir -p -m 755 base/salt && cp -r salt/* base/salt/

up:
vagrant up

clean:
rm -r base
$(MAKE) -C keys clean

.PHONY: base keys up clean
122 changes: 68 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Description
===========
# salt-sandbox

## Description

Salt Sandbox is a multi-VM [Vagrant](http://vagrantup.com/)-based
[Salt](http://saltstack.org/) development environment used for creating
Expand All @@ -9,7 +10,7 @@ execution capabilities.

Salt Sandbox will set up three separate virtual machines:

* _salt.example.com_ - the Salt master server
* _master.example.com_ - the Salt master server
* _minion1.example.com_ - the first Salt minion machine
* _minion2.example.com_ - the second Salt minion machine

Expand All @@ -18,99 +19,112 @@ based on node groups, top file environments, grain values, etc. You can
even test modules on different Linux distributions or release versions to
better match your production infrastructure.

Requirements
============
##Requirements

To use Salt Sandbox, you must have the following items installed and
To use `salt sandbox`, you must have the following items installed and
working:

* [VirtualBox](https://www.virtualbox.org/)
* [Vagrant](http://vagrantup.com/)
* [Vagrant](http://vagrantup.com/), version 1.8.1 or later
* [vagrant-hostmanager](https://github.com/smdahlen/vagrant-hostmanager)

Optionally, there are some `Makefile` rules included for convenience
that handle key generation and creating a simple `salt` state tree. To
use the included `Makefile`s, you'll want `GNU make`. The rules assume
that `openssl` is available to generate the private and public keys.

Salt Sandbox has been designed for and tested with Vagrant base boxes
The `salt sandbox` has been designed for and tested with `vagrant` base boxes
running:

* CentOS 5.7
* CentOS 6.7, 5.7
* Ubuntu 10.04 - Lucid Lynx

...although it may work just fine with other distributions/versions.
...although itshould work just fine with other distributions and releases.

Usage
=====
## Usage

Make sure you have a compatible Vagrant base box (if you don't have one
already, it will download a 64-bit CentOS 5.7 box for you), and then you
Make sure you have a compatible `vagrant` base box (if you don't have one
already, it will download a 64-bit _CentOS6.7_ box for you), and then you
should be good to clone this repo and go:

$ vagrant box list
centos57
$ git clone git://github.com/elasticdog/salt-sandbox.git
$ cd salt-sandbox/
```bash
$ git clone git://github.com/elasticdog/salt-sandbox.git
$ cd salt-sandbox/
```

Initial Startup
---------------
### Initial Startup

To bring up the Salt Sandbox environment, issue the following command:
To bring up the `salt sandbox` environment, issue the following command:

$ vagrant up
```bash
$make
```

The following tasks will be handled automatically:

1. The Salt master daemon will be installed and enabled on the master machine.
2. The Salt minion daemon will be installed and enabled on all three machines.
3. A host-only network will be set up with all machines knowing how to
communicate with each other.
4. All minion public keys will be automatically accepted by the master server.
5. The master server will utilize the `top.sls` file and `base/` directory that
exist **outside of the VMs** (in your salt-sandbox Git working directory) by
utilizing VirtualBox's shared folder feature.

All of this is handled using Vagrant's provisioning capabilities and is
controlled by the manifests under the `provision/` directory. In theory, you
1. The `salt master` daemon will be installed and enabled on the master machine.
2. The `salt minion` daemon will be installed and enabled on all three machines.
3. A private network will be set up with all machines knowing how to
communicate with each other.
4. All `minion` public keys will be automatically accepted by the `master` server.
5. The `master` server will utilize the `top.sls` file and `base/` directory that
exist **outside of the VMs** (in your salt-sandbox Git working directory) by
utilizing `virtualbox`'s shared folder feature.

All of this is handled using `vagrant`'s provisioning capabilities and is
controlled by the `Vagrantfile`. In theory, you
should never have to touch any of that code directly unless you're working to
improve Salt Sandbox.
improve `salt sandbox`.

If you wish to change the domain name of the VMs (it defaults to
_example.com_), edit the "domain" variable at the top of `Vagrantfile` and
`example.com`), edit the "domain" variable at the top of `Vagrantfile` and at the top of `keys/Makefile` and
reload the machines:

$ vim Vagrantfile
$ vagrant reload
```bash
$ make -C keys domain=otherdomain.com
$ vim Vagrantfile
$ vagrant reload
```

Developing New Modules
----------------------
### Developing New Modules

To start developing a new SLS module, just create the standard module structure
under `base/` in your salt-sandbox Git working directory (an example
"helloworld" module should exist there already). This directory is
automatically in the Salt master server's _file\_roots_ path, and any changes
To start developing a `salt` module, just create the standard module structure
under `base/` in your `salt sandbox` working directory (an example
`helloworld` module should exist there already). This directory is
automatically in the `salt master` server's `file\_roots` path, and any changes
will be picked up immediately.

$ mkdir -p base/mymodule
$ vim base/mymodule/init.sls
```bash
$ mkdir -p base/mymodule
$ vim base/mymodule/init.sls
```

To have your module actually applied to one or more of the minions, edit
the `top.sls` file and specify how it should be used during state
execution...that's it!

Check Your Handiwork
--------------------
### Check Your Handiwork

To log on to the virtual machines and see the result of your Salt modules, just
To log on to the virtual machines and see the result of your `salt` modules, just
use standard [Vagrant Multi-VM Environment](http://vagrantup.com/docs/multivm.html)
commands, and provide the proper VM name (`master`, `minion1`, or `minion2`):
commands, and provide the proper `VM` name (`master`, `minion1`, or `minion2`):

$ vagrant ssh master
```bash
$ vagrant ssh master
```

Then instruct all minions to execute a highstate call and apply any applicable
Then instruct all minions to execute a `highstate` call and apply any applicable
modules:

[vagrant@master ~]$ sudo salt '*' state.highstate
```bash
[vagrant@master ~]$ sudo salt '*' state.highstate
```

License
=======
## License

Salt Sandbox is provided under the terms of [The MIT
License](http://www.opensource.org/licenses/MIT).

Copyright © 2016, [Will Estes](westes575@gmail.com).

Copyright © 2012, [Aaron Bull Schaefer](mailto:aaron@elasticdog.com).
2 changes: 0 additions & 2 deletions TODO

This file was deleted.

82 changes: 48 additions & 34 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

domain = 'example.com'

Vagrant::Config.run do |config|
config.vm.define :master do |master_config|
master_config.vm.box = 'centos57'
master_config.vm.box_url = 'http://yum.mnxsolutions.com/vagrant/centos57_64.box'
master_config.vm.host_name = "salt.#{domain}"
master_config.vm.network :hostonly, '172.16.42.10'

master_config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'provision/manifests'
puppet.module_path = 'provision/modules'
end
end
Vagrant.configure("2") do |config|
config.hostmanager.enabled = true
config.hostmanager.manage_host = false
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true

config.vm.define :minion1 do |minion_config|
minion_config.vm.box = 'centos57'
minion_config.vm.box_url = 'http://yum.mnxsolutions.com/vagrant/centos57_64.box'
minion_config.vm.host_name = "minion1.#{domain}"
minion_config.vm.network :hostonly, '172.16.42.11'
config.vm.define "master", primary: true do |master|
master.vm.synced_folder "base/", "/srv", owner: "root", group: "root"
master.vm.box = "bento/centos-6.7"
master.vm.hostname = "master.#{domain}"
master.hostmanager.aliases = %W(salt salt.#{domain})
master.vm.network "private_network", ip: "172.16.42.10"
master.vm.provision :salt do |salt|
salt.seed_master = {
"master.#{domain}" => "keys/master.#{domain}.pub",
"minion1.#{domain}" => "keys/minion1.#{domain}.pub",
"minion2.#{domain}" => "keys/minion2.#{domain}.pub",
}
salt.install_master = true
salt.run_highstate = true
salt.master_key = "keys/master.pem"
salt.master_pub = "keys/master.pub"
salt.minion_id = "master.#{domain}.pub"
salt.minion_key = "keys/master.#{domain}.pem"
salt.minion_pub = "keys/master.#{domain}.pub"
end
end

minion_config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'provision/manifests'
puppet.module_path = 'provision/modules'
end
config.vm.define "minion1" do |minion1|
minion1.vm.box = "bento/centos-6.7"
minion1.vm.network "private_network", ip: "172.16.42.11"
minion1.vm.hostname = "minion1.#{domain}"
minion1.vm.provision :salt do |salt|
salt.minion_key = "keys/minion1.#{domain}.pem"
salt.minion_pub = "keys/minion1.#{domain}.pub"
salt.install_master = false
salt.run_highstate = true
end
end

config.vm.define :minion2 do |minion_config|
minion_config.vm.box = 'centos57'
minion_config.vm.box_url = 'http://yum.mnxsolutions.com/vagrant/centos57_64.box'
minion_config.vm.host_name = "minion2.#{domain}"
minion_config.vm.network :hostonly, '172.16.42.12'

minion_config.vm.provision :puppet do |puppet|
puppet.manifests_path = 'provision/manifests'
puppet.module_path = 'provision/modules'
end
config.vm.define "minion2" do |minion2|
minion2.vm.box = "bento/centos-6.7"
minion2.vm.network "private_network", ip: "172.16.42.12"
minion2.vm.hostname = "minion2.#{domain}"
minion2.vm.provision :salt do |salt|
salt.minion_key = "keys/minion2.#{domain}.pem"
salt.minion_pub = "keys/minion2.#{domain}.pub"
salt.install_master = false
salt.run_highstate = true
end
end

end
14 changes: 14 additions & 0 deletions keys/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
domain = example.com

keyfiles = master.pem master.pub master.$(domain).pem master.$(domain).pub minion1.$(domain).pem minion1.$(domain).pub minion2.$(domain).pem minion2.$(domain).pub

all: $(keyfiles)

%.pem:
openssl genpkey -algorithm RSA -out $@ -pkeyopt rsa_keygen_bits:2048

%.pub: %.pem
openssl rsa -in $< -pubout -out $@

clean:
rm -f $(keyfiles)
16 changes: 0 additions & 16 deletions provision/manifests/default.pp

This file was deleted.

13 changes: 0 additions & 13 deletions provision/modules/mirrors/files/epel-salt.repo

This file was deleted.

44 changes: 0 additions & 44 deletions provision/modules/mirrors/manifests/apt.pp

This file was deleted.

Loading