vagrant-ansible 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +9 -0
- data/README.md +139 -0
- data/Rakefile +22 -0
- data/Vagrantfile.sample +22 -0
- data/lib/vagrant-ansible.rb +5 -0
- data/lib/vagrant-ansible/provisioner.rb +68 -0
- data/lib/vagrant_init.rb +1 -0
- metadata +91 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
## vagrant-ansible
|
2
|
+
|
3
|
+
https://github.com/dsander/vagrant-ansible
|
4
|
+
|
5
|
+
Vagrant-ansible is a provisioning plugin for [Vagrant](http://vagrantup.com/), that makes developing and testing [playbooks](http://ansible.github.com/playbooks.html) for [ansible](http://ansible.github.com/) easy.
|
6
|
+
|
7
|
+
vagrant-ansible was inspired by [Sous Chef](https://github.com/michaelklishin/sous-chef), and borrowed a bit of its documentation.
|
8
|
+
|
9
|
+
|
10
|
+
## How it works
|
11
|
+
|
12
|
+
With vagrant-ansible, you use Vagrant and a locally running VirtualBox VM to develop and test your playbooks. vagrant-ansible can use any collection of playbooks you are using for commercial projects or anything else.
|
13
|
+
|
14
|
+
With vagrant-ansible, you provision a locally running virtual machine managed by [Vagrant](http://vagrantup.com) in just one command. The process is
|
15
|
+
set up to shorten the feedback loop:
|
16
|
+
|
17
|
+
* Modify your playbook plays (or templates/files in them)
|
18
|
+
* Run provisioning
|
19
|
+
* See and verify the result
|
20
|
+
* Rinse and repeat
|
21
|
+
|
22
|
+
Once you are done with your playbooks, just push them to a source control repository or rsync them to your server. Then destroy VM environment
|
23
|
+
you were using in one command. Or just power off the VM and come back to work with it later.
|
24
|
+
|
25
|
+
|
26
|
+
## Dependencies
|
27
|
+
|
28
|
+
vagrant-ansible uses [Vagrant](http://vagrantup.com) and thus relies on [Virtual Box](http://virtualbox.org), you also need to have [ansible](http://ansible.github.com/gettingstarted.html) installed.
|
29
|
+
|
30
|
+
|
31
|
+
## Getting started with vagrant-ansible
|
32
|
+
|
33
|
+
First install [VirtualBox 4.1.x](https://www.virtualbox.org/wiki/Downloads):
|
34
|
+
|
35
|
+
* For [Mac OS X](http://dlc.sun.com.edgesuite.net/virtualbox/4.1.14/VirtualBox-4.1.14-77440-OSX.dmg)
|
36
|
+
* For [64-bit Linux distributions](http://download.virtualbox.org/virtualbox/4.1.14/)
|
37
|
+
|
38
|
+
Install ansible using the instructions on the ansible [homepage](http://ansible.github.com/gettingstarted.html)
|
39
|
+
|
40
|
+
Then install the vagrant gem:
|
41
|
+
|
42
|
+
gem install vagrant --version ">= 1.0"
|
43
|
+
|
44
|
+
Then install the vagrant-ansible gem:
|
45
|
+
|
46
|
+
gem install vagrant-ansible
|
47
|
+
|
48
|
+
Create a playbook or just clone an existing repository:
|
49
|
+
|
50
|
+
git clone https://github.com/cocoy/ansible-playbooks.git
|
51
|
+
|
52
|
+
Now change into the ansible-playbooks directory and download the example Vagrantfile:
|
53
|
+
|
54
|
+
cd ansible-playbooks
|
55
|
+
wget https://raw.github.com/dsander/vagrant-ansible/master/Vagrantfile.sample -O Vagrantfile
|
56
|
+
|
57
|
+
Before you can run your playbook for the first time, you have to change the remote user to 'vagrant' in your playbook. This is necessary because the user specified in the playbook can not be overridden via command line options.
|
58
|
+
|
59
|
+
....
|
60
|
+
- hosts: web-servers
|
61
|
+
user: vagrant
|
62
|
+
.....
|
63
|
+
|
64
|
+
|
65
|
+
Create a 32-bit Ubuntu virtual machine you will be developing playbooks in:
|
66
|
+
|
67
|
+
vagrant up
|
68
|
+
|
69
|
+
You will notice that the VM is automatically created, and nginx-ubuntu playbook is executed.
|
70
|
+
|
71
|
+
|
72
|
+
Have a look at your Vagrantfile, it will look like this:
|
73
|
+
|
74
|
+
Vagrant::Config.run do |config|
|
75
|
+
config.vm.box = "oneiric32_base"
|
76
|
+
config.vm.box_url = "http://files.travis-ci.org/boxes/bases/oneiric32_base.box"
|
77
|
+
|
78
|
+
config.vm.customize ["modifyvm", :id, "--memory", "512"]
|
79
|
+
|
80
|
+
# This is only necessary if your CPU does not support VT-x or you run virtualbox
|
81
|
+
# inside virtualbox
|
82
|
+
config.vm.customize ["modifyvm", :id, "--vtxvpid", "off"]
|
83
|
+
|
84
|
+
# You can adjust this to the amount of CPUs your system has available
|
85
|
+
config.vm.customize ["modifyvm", :id, "--cpus", "1"]
|
86
|
+
|
87
|
+
config.vm.provision :ansible do |ansible|
|
88
|
+
# point Vagrant at the location of your playbook you want to run
|
89
|
+
ansible.playbook = "nginx-ubuntu.yml"
|
90
|
+
|
91
|
+
# the Vagrant VM will be put in this host group change this should
|
92
|
+
# match the host group in your playbook you want to test
|
93
|
+
ansible.hosts = "web-servers"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
You can now change the playbook to run, or create new tasks in it. To rerun, the provisioning just run:
|
98
|
+
|
99
|
+
vagrant provision
|
100
|
+
|
101
|
+
|
102
|
+
Once provisioning finishes, ssh into the VM to check what the environment looks like:
|
103
|
+
|
104
|
+
vagrant ssh
|
105
|
+
|
106
|
+
When you are done with your work on the cookbook you can either power off the VM to use it later with
|
107
|
+
|
108
|
+
vagrant halt
|
109
|
+
|
110
|
+
or destroy it completely with
|
111
|
+
|
112
|
+
vagrant destroy
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
## LICENSE:
|
117
|
+
|
118
|
+
(The MIT License)
|
119
|
+
|
120
|
+
Copyright (c) 2012 Dominik Sander
|
121
|
+
|
122
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
123
|
+
a copy of this software and associated documentation files (the
|
124
|
+
'Software'), to deal in the Software without restriction, including
|
125
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
126
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
127
|
+
permit persons to whom the Software is furnished to do so, subject to
|
128
|
+
the following conditions:
|
129
|
+
|
130
|
+
The above copyright notice and this permission notice shall be
|
131
|
+
included in all copies or substantial portions of the Software.
|
132
|
+
|
133
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
134
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
135
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
136
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
137
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
138
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
139
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
|
6
|
+
Hoe.plugin :git
|
7
|
+
Hoe.plugin :gemspec
|
8
|
+
Hoe.plugin :bundler
|
9
|
+
Hoe.plugin :gemcutter
|
10
|
+
Hoe.plugins.delete :rubyforge
|
11
|
+
|
12
|
+
Hoe.spec 'vagrant-ansible' do
|
13
|
+
developer('Dominik Sander', 'git@dsander.de')
|
14
|
+
self.description ="Develop & test your ansible playbooks with Vagrant"
|
15
|
+
self.summary = "Vagrant-ansible is a provisioning plugin for Vagrant, that makes developing and testing playbooks for ansible easy."
|
16
|
+
|
17
|
+
self.readme_file = 'README.md'
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
|
+
self.extra_deps << ["vagrant"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# vim: syntax=ruby
|
data/Vagrantfile.sample
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Vagrant::Config.run do |config|
|
2
|
+
config.vm.box = "oneiric32_base"
|
3
|
+
config.vm.box_url = "http://files.travis-ci.org/boxes/bases/oneiric32_base.box"
|
4
|
+
|
5
|
+
config.vm.customize ["modifyvm", :id, "--memory", "512"]
|
6
|
+
|
7
|
+
# This is only necessary if your CPU does not support VT-x or you run virtualbox
|
8
|
+
# inside virtualbox
|
9
|
+
config.vm.customize ["modifyvm", :id, "--vtxvpid", "off"]
|
10
|
+
|
11
|
+
# You can adjust this to the amount of CPUs your system has available
|
12
|
+
config.vm.customize ["modifyvm", :id, "--cpus", "1"]
|
13
|
+
|
14
|
+
config.vm.provision :ansible do |ansible|
|
15
|
+
# point Vagrant at the location of your playbook you want to run
|
16
|
+
ansible.playbook = "nginx-ubuntu.yml"
|
17
|
+
|
18
|
+
# the Vagrant VM will be put in this host group change this should
|
19
|
+
# match the host group in your playbook you want to test
|
20
|
+
ansible.hosts = "web-servers"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Provisioners
|
5
|
+
class Ansible < Base
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
include Util::SafeExec
|
8
|
+
|
9
|
+
class Config < Vagrant::Config::Base
|
10
|
+
attr_accessor :playbook
|
11
|
+
attr_accessor :hosts
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate(env, errors)
|
18
|
+
# Validate that the parameters are properly set
|
19
|
+
if playbook.nil?
|
20
|
+
errors.add(I18n.t("vagrant.provisioners.ansible.no_playbook"))
|
21
|
+
end
|
22
|
+
if hosts.nil?
|
23
|
+
errors.add(I18n.t("vagrant.provisioners.ansible.no_hosts"))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.config_class
|
29
|
+
Config
|
30
|
+
end
|
31
|
+
|
32
|
+
# This methods yield the path to a temporally created inventory
|
33
|
+
# file.
|
34
|
+
def with_inventory_file(ssh)
|
35
|
+
begin
|
36
|
+
forward = env[:vm].config.vm.forwarded_ports.select do |x|
|
37
|
+
x[:guestport] == ssh.guest_port
|
38
|
+
end.first[:hostport]
|
39
|
+
file = Tempfile.new('inventory')
|
40
|
+
file.write("[#{config.hosts}]\n")
|
41
|
+
file.write("#{ssh.host}:#{forward}")
|
42
|
+
file.fsync
|
43
|
+
file.close
|
44
|
+
yield file.path
|
45
|
+
ensure
|
46
|
+
file.unlink
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def provision!
|
51
|
+
ssh = env[:vm].config.ssh
|
52
|
+
|
53
|
+
with_inventory_file(ssh) do |inventory_file|
|
54
|
+
puts ["ansible-playbook",
|
55
|
+
"--user=#{ssh.username}",
|
56
|
+
"--inventory-file=#{inventory_file}",
|
57
|
+
"--private-key=#{env[:vm].env.default_private_key_path}",
|
58
|
+
config.playbook].join(' ')
|
59
|
+
safe_exec("ansible-playbook",
|
60
|
+
"--user=#{ssh.username}",
|
61
|
+
"--inventory-file=#{inventory_file}",
|
62
|
+
"--private-key=#{env[:vm].env.default_private_key_path}",
|
63
|
+
config.playbook)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/vagrant_init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'vagrant-ansible'
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-ansible
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dominik Sander
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: &12257060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12257060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &12270200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.10'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12270200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hoe
|
38
|
+
requirement: &12267880 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *12267880
|
47
|
+
description: Develop & test your ansible playbooks with Vagrant
|
48
|
+
email:
|
49
|
+
- git@dsander.de
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- Manifest.txt
|
54
|
+
files:
|
55
|
+
- .autotest
|
56
|
+
- CHANGELOG.md
|
57
|
+
- Manifest.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- Vagrantfile.sample
|
61
|
+
- lib/vagrant-ansible.rb
|
62
|
+
- lib/vagrant-ansible/provisioner.rb
|
63
|
+
- lib/vagrant_init.rb
|
64
|
+
homepage: https://github.com/dsander/vagrant-ansible
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.md
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: vagrant-ansible
|
86
|
+
rubygems_version: 1.8.11
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Vagrant-ansible is a provisioning plugin for Vagrant, that makes developing
|
90
|
+
and testing playbooks for ansible easy.
|
91
|
+
test_files: []
|