Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Update: import vagrant cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed May 18, 2015
1 parent 04bf9d6 commit ed03599
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -20,6 +20,7 @@ AllCops:
- 'nodejs/**/*'
- 'logrotate/**/*'
- 'virtualbox/**/*'
- 'vagrant/**/*'

Style/SingleSpaceBeforeFirstArg:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions VERSIONS.md
Expand Up @@ -15,4 +15,5 @@ xml| [1.2.4](https://github.com/opscode-cookbooks/xml/tree/v1.2.4) |
python | [master](https://github.com/poise/python/commit/56424ab64b06f584c13dba2dbb1cc5369faf20f4) |
sinopia | [0.3.0](https://github.com/BarthV/sinopia-cookbook/releases/tag/0.3.0) | removed dependency `user` cookbook
supervisor | [master](https://github.com/poise/supervisor/commit/0806cb6fccfdaf3da5959ce9c2bc42287ad50b26) |
vagrant | 0.2.2 | disabled dependency on dmg and windows
virtualbox | 1.0.3 | disabled dependency on yum, dmg, windows and apache2
11 changes: 11 additions & 0 deletions vagrant/CHANGELOG.md
@@ -0,0 +1,11 @@
## 0.2.2:

* Fix platform_family, redhat is not a family, rhel is. (#18)

## 0.2.0:

* Add `uninstall_gem` recipe to remove vagrant (1.0) gem.

## 0.1.1:

* Initial release of vagrant
148 changes: 148 additions & 0 deletions vagrant/README.md
@@ -0,0 +1,148 @@
vagrant Cookbook
================

Installs Vagrant 1.6+ and manages vagrant plugins w/ a custom
resource.

* Vagrant: http://www.vagrantup.com/

This cookbook is not intended to be used for vagrant "1.0" (gem
install) versions. A recipe is provided for removing the gem, see __Recipes__.

This cookbook is not supported for installing versions of Vagrant older than 1.6.

Requirements
------------

Tested with Test Kitchen:

* Debian 7.6
* Ubuntu 14.04
* CentOS 6.5

May work on other Debian/RHEL family distributions with or without modification.

Support exists for Windows and OS X but this has not yet been added to test-kitchen (`.kitchen.yml`).

The URL and Checksum attributes must be set, see __Attributes__

Because Vagrant is installed as a native system package, Chef must run as a privileged user (e.g., root).

Attributes
==========

The following attributes *must* be set. See `.kitchen.yml` for example values.

* `node['vagrant']['url']` - URL to the Vagrant installation package.
* `node['vagrant']['checksum']` - SHA256 checksum of the Vagrant
installation package.

If the node is Windows, the MSI version must be set. This is used by
the `windows_package` resource to determine if the package is
installed.

* `node['vagrant']['msi_version']` - Version string of the installed
MSI "package" on Windows.

The following attribute is optional.

* `node['vagrant']['plugins']` - An array of plugins. The elements in
the array can be a string or a hash. String elements should be the
names of plugins to install. Hash elements should have two keys,
"name" and "version", for the plugin name and its version to
install. This is used by the `vagrant_plugin` resource in the
default recipe.

Resources
=========

This cookbook includes the `vagrant_plugin` resource, for managing
vagrant plugins.

## vagrant_plugin

### Actions

- `:install`: installs the specified plugin. Default.
- `:uninstall`: uninstalls the specified plugin
- `:remove`: uninstalls the specified plugin

### Attribute Parameters

- `:plugin_name`: name attribute, the name of the plugin, e.g.
"vagrant-omnibus".
- `:version`: version of the plugin to installed, must be specified as
a string, e.g., "1.0.2"

### Examples

vagrant_plugin "vagrant-omnibus"

vagrant_plugin "vagrant-berkshelf"
version "1.2.0"
end

Recipes
=======

## default

The default recipe includes the platform-family specific recipe to
install Vagrant. It then iterates over the
`node['vagrant']['plugins']` attribute to install any required vagrant
plugins.

## debian, fedora, mac_os_x, rhel, windows

These are the platform family recipes included by the default recipe.
The `fedora` recipe will include `rhel`.

## uninstall_gem

This recipe will attempt to uninstall the `vagrant` gem with the
`gem_package` and `chef_gem` resources. Meaning, it will use the `gem`
binary in the `PATH` of the shell executing Chef to uninstall, and
then use Chef's built-in RubyGems to uninstall. If you have a
customized Ruby environment, such as with rbenv or rvm (or other), you
may need to manually remove and clean up anything leftover, such as
running `rbenv rehash`. Likewise, if you have multiple copies of the
vagrant gem installed, you'll need to clean up all versions. This
recipe won't support such craziness :-).

Usage
=====

Set the url and checksum attributes on the node. Do this in a role, or
a "wrapper" cookbook.

Then include the default recipe on the node's run list.

To specify plugins for installation in the default recipe, specify an
array for the `node['vagrant']['plugins']` attribute. For example, to
install the `vagrant-omnibus` plugin (any version) and version "1.2.0"
of the `vagrant-berkshelf` plugin:

node.set['vagrant']['plugins'] = [
"vagrant-omnibus",
{"name" => "vagrant-berkshelf", "version" => "1.2.0"}
]

See the attribute description above.

License and Authors
-------------------

* Author:: Joshua Timberman <opensource@housepub.org>
* Copyright (c) 2013-2014, Joshua Timberman

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
23 changes: 23 additions & 0 deletions vagrant/attributes/default.rb
@@ -0,0 +1,23 @@
#
# Author:: Joshua Timberman <opensource@housepub.org>
# Copyright (c) 2013-2014, Joshua Timberman
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default['vagrant']['version'] = '1.6.5'
default['vagrant']['url'] = vagrant_package_uri(node['vagrant']['version'])
default['vagrant']['checksum'] = vagrant_sha256sum(node['vagrant']['version'])
default['vagrant']['plugins'] = []
default['vagrant']['msi_version'] = ''
50 changes: 50 additions & 0 deletions vagrant/libraries/helpers.rb
@@ -0,0 +1,50 @@
#
# Author:: Joshua Timberman <opensource@housepub.org>
# Copyright:: Copyright (c) 2014, Joshua Timberman
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'uri'
require 'open-uri'

def vagrant_base_uri
'https://dl.bintray.com/mitchellh/vagrant/'
end

def vagrant_platform_package(vers = nil)
case node['os']
when 'darwin'
"vagrant_#{vers}.dmg"
when 'windows'
"vagrant_#{vers}.msi"
when 'linux'
case node['platform_family']
when 'debian'
"vagrant_#{vers}_x86_64.deb"
when 'fedora', 'rhel'
"vagrant_#{vers}_x86_64.rpm"
end
end
end

def vagrant_sha256sum(vers = nil)
# fetch the version-specific sha256sum file
# grep for the platform-specific package name
sha256sums = open(URI.join(vagrant_base_uri, "#{vers}_SHA256SUMS?direct"))
sha256sums.readlines.grep(/#{vagrant_platform_package(vers)}/)[0].split.first
end

def vagrant_package_uri(vers = nil)
URI.join(vagrant_base_uri, vagrant_platform_package(vers)).to_s
end
35 changes: 35 additions & 0 deletions vagrant/metadata.json
@@ -0,0 +1,35 @@
{
"name": "vagrant",
"version": "0.2.2",
"description": "Installs/Configures vagrant",
"long_description": "",
"maintainer": "Joshua Timberman",
"maintainer_email": "cookbooks@housepub.org",
"license": "Apache 2.0",
"platforms": {
"debian": ">= 6.0",
"ubuntu": ">= 12.04",
"redhat": ">= 6.3",
"centos": ">= 6.4"
},
"dependencies": {
"dmg": ">= 0.0.0",
"windows": ">= 0.0.0"
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
}
}
14 changes: 14 additions & 0 deletions vagrant/metadata.rb
@@ -0,0 +1,14 @@
name 'vagrant'
maintainer 'Joshua Timberman'
maintainer_email 'cookbooks@housepub.org'
license 'Apache 2.0'
description 'Installs/Configures vagrant'
version '0.2.2'

supports 'debian', '>= 6.0'
supports 'ubuntu', '>= 12.04'
supports 'redhat', '>= 6.3'
supports 'centos', '>= 6.4'

#depends 'dmg'
#depends 'windows'
50 changes: 50 additions & 0 deletions vagrant/providers/plugin.rb
@@ -0,0 +1,50 @@
require 'chef/mixin/shell_out'
include Chef::Mixin::ShellOut

def load_current_resource
@current_resource = Chef::Resource::VagrantPlugin.new(new_resource)
vp = shell_out("vagrant plugin list")
if vp.stdout.include?(new_resource.plugin_name)
@current_resource.installed(true)
@current_resource.installed_version(vp.stdout.split[1].gsub(/[\(\)]/, ''))
end
@current_resource
end

action :install do
unless installed?
plugin_args = ""
plugin_args += "--plugin-version #{new_resource.version}" if new_resource.version
shell_out("vagrant plugin install #{new_resource.plugin_name} #{plugin_args}")
new_resource.updated_by_last_action(true)
end
end

action :remove do
uninstall if @current_resource.installed
new_resource.updated_by_last_action(true)
end

action :uninstall do
uninstall if @current_resource.installed
new_resource.updated_by_last_action(true)
end

def uninstall
shell_out("vagrant plugin uninstall #{new_resource.plugin_name}")
end

def installed?
@current_resource.installed && version_match
end

def version_match
# if the version is specified, we need to check if it matches what
# is installed already
if new_resource.version
@current_resource.installed_version == new_resource.version
else
# the version matches otherwise because it's installed
true
end
end
9 changes: 9 additions & 0 deletions vagrant/recipes/debian.rb
@@ -0,0 +1,9 @@
remote_file "#{Chef::Config[:file_cache_path]}/vagrant.deb" do
source node['vagrant']['url']
checksum node['vagrant']['checksum']
notifies :install, "dpkg_package[vagrant]", :immediately
end

dpkg_package "vagrant" do
source "#{Chef::Config[:file_cache_path]}/vagrant.deb"
end
34 changes: 34 additions & 0 deletions vagrant/recipes/default.rb
@@ -0,0 +1,34 @@
#
# Cookbook Name:: vagrant
# Recipe:: default
#
# Copyright 2013, Joshua Timberman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "vagrant::#{node['platform_family']}"

node['vagrant']['plugins'].each do |plugin|
if plugin.respond_to?(:keys)

vagrant_plugin plugin['name'] do
version plugin['version']
end

else

vagrant_plugin plugin

end
end
1 change: 1 addition & 0 deletions vagrant/recipes/fedora.rb
@@ -0,0 +1 @@
include_recipe "vagrant::rhel"

0 comments on commit ed03599

Please sign in to comment.