vagrant-ansible-local 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ *.rbc
2
+ .config
3
+ .yardoc
4
+ Gemfile.lock
5
+ InstalledFiles
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ lib/bundler/man
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # Bundler/Rubygems
17
+ *.gem
18
+ .bundle
19
+ pkg/*
20
+ tags
21
+ Gemfile.lock
22
+
23
+ # Vagrant
24
+ .vagrant
25
+ ansible
26
+ Vagrantfile
27
+ !example_box/Vagrantfile
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-ansible-local.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # We depend on Vagrant for development, but we don't add it as a
8
+ # gem dependency because we expect to be installed within the
9
+ # Vagrant environment itself using `vagrant plugin`.
10
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.3.5"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jérémie Augustin <jeremie.augustin@pixel-cookers.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Vagrant Ansible Local
2
+
3
+ This Vagrant plugin allow provisioning your VM with ansible playbooks directly from the guest VM using --connection=local
4
+
5
+ ## Installation
6
+
7
+ install this vagrant plugin by running (won't work yet)
8
+
9
+ vagrant plugin install vagrant-ansible-local
10
+
11
+ ## Usage
12
+
13
+ Configure your VagrantFile with the `ansibleLocal` provisioner:
14
+
15
+ config.vm.provision :ansibleLocal, :playbook => "ansible/ansible.yml"
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create new Pull Request
24
+
25
+
26
+ ## TODO
27
+
28
+ * cleanup parameters
29
+ * auto build or mount `inventory-file` and prevent issue with non executable file mounted with 777
30
+ * add command for running ansible-playbook on demand
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,16 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-ansible-local/plugin"
4
+
5
+ module VagrantPlugins
6
+ module AnsibleLocal
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-ansible-local", __FILE__))
8
+
9
+ # This returns the path to the source of this plugin.
10
+ #
11
+ # @return [Pathname]
12
+ def self.source_root
13
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,105 @@
1
+ module VagrantPlugins
2
+ module AnsibleLocal
3
+ class Config < Vagrant.plugin("2", :config)
4
+ attr_accessor :playbook
5
+ attr_accessor :guest_folder
6
+ attr_accessor :extra_vars
7
+ attr_accessor :inventory_path
8
+ attr_accessor :ask_sudo_pass
9
+ attr_accessor :limit
10
+ attr_accessor :sudo
11
+ attr_accessor :sudo_user
12
+ attr_accessor :verbose
13
+ attr_accessor :tags
14
+ attr_accessor :skip_tags
15
+ attr_accessor :start_at_task
16
+ attr_accessor :host_key_checking
17
+
18
+ # Joker attribute, used to pass unsupported arguments to ansible anyway
19
+ attr_accessor :raw_arguments
20
+
21
+ def initialize
22
+ super
23
+
24
+ @playbook = UNSET_VALUE
25
+ @guest_folder = UNSET_VALUE
26
+ @extra_vars = UNSET_VALUE
27
+ @inventory_path = UNSET_VALUE
28
+ @ask_sudo_pass = UNSET_VALUE
29
+ @limit = UNSET_VALUE
30
+ @sudo = UNSET_VALUE
31
+ @sudo_user = UNSET_VALUE
32
+ @verbose = UNSET_VALUE
33
+ @tags = UNSET_VALUE
34
+ @skip_tags = UNSET_VALUE
35
+ @start_at_task = UNSET_VALUE
36
+ @raw_arguments = UNSET_VALUE
37
+ @host_key_checking = "true"
38
+ end
39
+
40
+ def finalize!
41
+ super
42
+
43
+ @playbook = nil if @playbook == UNSET_VALUE
44
+ @guest_folder = "/tmp/vagrant-ansible-local" if @guest_folder == UNSET_VALUE
45
+ @extra_vars = nil if @extra_vars == UNSET_VALUE
46
+ @inventory_path = nil if @inventory_path == UNSET_VALUE
47
+ @ask_sudo_pass = nil if @ask_sudo_pass == UNSET_VALUE
48
+ @limit = nil if @limit == UNSET_VALUE
49
+ @sudo = nil if @sudo == UNSET_VALUE
50
+ @sudo_user = nil if @sudo_user == UNSET_VALUE
51
+ @verbose = nil if @verbose == UNSET_VALUE
52
+ @tags = nil if @tags == UNSET_VALUE
53
+ @skip_tags = nil if @skip_tags == UNSET_VALUE
54
+ @start_at_task = nil if @start_at_task == UNSET_VALUE
55
+ @raw_arguments = nil if @raw_arguments == UNSET_VALUE
56
+ @host_key_checking = nil if @host_key_checking == UNSET_VALUE
57
+
58
+ if @extra_vars && @extra_vars.is_a?(Hash)
59
+ @extra_vars.each do |k, v|
60
+ @extra_vars[k] = v.to_s
61
+ end
62
+ end
63
+
64
+ puts("finalize")
65
+ puts(@guest_folder)
66
+ end
67
+
68
+ def validate(machine)
69
+ errors = _detected_errors
70
+
71
+ # Validate that a playbook path was provided
72
+ if !playbook
73
+ errors << I18n.t("vagrant.provisioners.ansible.no_playbook")
74
+ end
75
+
76
+ # Validate the existence of said playbook on the host
77
+ if playbook
78
+ expanded_path = Pathname.new(playbook).expand_path(machine.env.root_path)
79
+ if !expanded_path.file?
80
+ errors << I18n.t("vagrant.provisioners.ansible.playbook_path_invalid",
81
+ :path => expanded_path)
82
+ end
83
+ end
84
+
85
+ # Validate that extra_vars is a hash, if set
86
+ if extra_vars
87
+ if !extra_vars.kind_of?(Hash)
88
+ errors << I18n.t("vagrant.provisioners.ansible.extra_vars_not_hash")
89
+ end
90
+ end
91
+
92
+ # Validate the existence of the inventory_path, if specified
93
+ if inventory_path
94
+ expanded_path = Pathname.new(inventory_path).expand_path(machine.env.root_path)
95
+ if !expanded_path.exist?
96
+ errors << I18n.t("vagrant.provisioners.ansible.inventory_path_invalid",
97
+ :path => expanded_path)
98
+ end
99
+ end
100
+
101
+ { "ansible-local provisioner" => errors }
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,23 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module AnsibleLocal
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "ansible_local"
7
+ description <<-DESC
8
+ Provides support for provisioning your virtual machines with
9
+ Ansible playbooks directly from the guest VM using --connection=local.
10
+ DESC
11
+
12
+ config(:ansibleLocal, :provisioner) do
13
+ require File.expand_path("../config", __FILE__)
14
+ Config
15
+ end
16
+
17
+ provisioner(:ansibleLocal) do
18
+ require File.expand_path("../provisioner", __FILE__)
19
+ Provisioner
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,87 @@
1
+ module VagrantPlugins
2
+ module AnsibleLocal
3
+ class Provisioner < Vagrant.plugin("2", :provisioner)
4
+
5
+ def configure(root_config)
6
+ playbook_path = Pathname.new(File.dirname(config.playbook)).expand_path(@machine.env.root_path)
7
+
8
+ #folder_opts = {}
9
+ #folder_opts[:nfs] = true if config.nfs
10
+ #folder_opts[:owner] = "root" if !folder_opts[:nfs]
11
+
12
+ # Share the playbook directory with the guest
13
+ root_config.vm.synced_folder(playbook_path, config.guest_folder.to_s)
14
+ end
15
+
16
+ def provision
17
+ # ssh = @machine.ssh_info
18
+
19
+ # Connect with Vagrant user (unless --user or --private-key are overidden by 'raw_arguments')
20
+ #options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}]
21
+ options = %W[--connection=local]
22
+
23
+ # Joker! Not (yet) supported arguments can be passed this way.
24
+ options << "#{config.raw_arguments}" if config.raw_arguments
25
+
26
+ # Append Provisioner options (highest precedence):
27
+ if config.extra_vars
28
+ extra_vars = config.extra_vars.map do |k,v|
29
+ v = v.gsub('"', '\\"')
30
+ if v.include?(' ')
31
+ v = v.gsub("'", "\\'")
32
+ v = "'#{v}'"
33
+ end
34
+
35
+ "#{k}=#{v}"
36
+ end
37
+ options << "--extra-vars=\"#{extra_vars.join(" ")}\""
38
+ end
39
+
40
+ # options << "--inventory-file=#{self.setup_inventory_file}"
41
+ # options << "--sudo" if config.sudo
42
+ # options << "--sudo-user=#{config.sudo_user}" if config.sudo_user
43
+ options << "#{self.get_verbosity_argument}" if config.verbose
44
+ # options << "--ask-sudo-pass" if config.ask_sudo_pass
45
+ options << "--tags=#{as_list_argument(config.tags)}" if config.tags
46
+ options << "--skip-tags=#{as_list_argument(config.skip_tags)}" if config.skip_tags
47
+ options << "--limit=#{as_list_argument(config.limit)}" if config.limit
48
+ options << "--start-at-task=#{config.start_at_task}" if config.start_at_task
49
+
50
+ # Assemble the full ansible-playbook command
51
+ command = "export ANSIBLE_FORCE_COLOR=true\n"
52
+ command += "export ANSIBLE_HOST_KEY_CHECKING=#{config.host_key_checking}\n"
53
+ command += "export PYTHONUNBUFFERED=1\n"
54
+ command += (%w(ansible-playbook) << (File.join(config.guest_folder, File.basename(config.playbook).to_s)) << options).flatten.join(' ')
55
+
56
+
57
+
58
+ @machine.communicate.tap do |comm|
59
+ @machine.env.ui.info(command, :new_line => true, :prefix => false)
60
+
61
+ # Execute it with sudo
62
+ comm.execute(command, sudo: config.privileged) do |type, data|
63
+ if [:stderr, :stdout].include?(type)
64
+ @machine.env.ui.info(data, :new_line => false, :prefix => false)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ protected
71
+
72
+ def get_verbosity_argument
73
+ if config.verbose.to_s =~ /^v+$/
74
+ # ansible-playbook accepts "silly" arguments like '-vvvvv' as '-vvvv' for now
75
+ return "-#{config.verbose}"
76
+ else
77
+ # safe default, in case input strays
78
+ return '-v'
79
+ end
80
+ end
81
+
82
+ def as_list_argument(v)
83
+ v.kind_of?(Array) ? v.join(',') : v
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module AnsibleLocal
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-ansible-local/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-ansible-local"
8
+ spec.version = Vagrant::AnsibleLocal::VERSION
9
+ spec.authors = ["jaugustin"]
10
+ spec.email = ["jeremie.augustin@pixel-cookers.com"]
11
+ spec.description = %q{"vagrant plugin to provision VM with ansible in local mode"}
12
+ spec.summary = %q{"vagrant plugin to provision VM with ansible in local mode"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ansible-local
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jaugustin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! '"vagrant plugin to provision VM with ansible in local mode"'
47
+ email:
48
+ - jeremie.augustin@pixel-cookers.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - Vagrantfile
59
+ - lib/vagrant-ansible-local.rb
60
+ - lib/vagrant-ansible-local/config.rb
61
+ - lib/vagrant-ansible-local/plugin.rb
62
+ - lib/vagrant-ansible-local/provisioner.rb
63
+ - lib/vagrant-ansible-local/version.rb
64
+ - vagrant-ansible-local.gemspec
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
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
+ segments:
79
+ - 0
80
+ hash: 551987535
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 551987535
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: ! '"vagrant plugin to provision VM with ansible in local mode"'
96
+ test_files: []