vagrant-ansible-local-privileged 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f1794fcd25ae7b24cf652dc8522ae34cb7f3b4a
4
+ data.tar.gz: f4b4b3bb14197fd6c9c2849def8e75b012ec5092
5
+ SHA512:
6
+ metadata.gz: 2ae278a38d6c6ed16bfd874fbb71be9274eb254d076939e11b4b79aae0701a705d6a16ef583bdd336b439c141bcb56e74d2e96de030b1a742547e2c3ea497eca
7
+ data.tar.gz: a0b980cf63191862ab29db4934b3ea2a331def0f14fbd1a8403995428f2820f2a4f9750e4e9a22a5c3ebc2b5d1f28aaf8451a14787ce552ecae527632ac1a922
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,42 @@
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
8
+
9
+ vagrant plugin install vagrant-ansible-local
10
+
11
+ ## requirement
12
+
13
+ Your vagrant box should have ansible installed on it, if it's not the case you could use to shell provisioner to install it.
14
+
15
+ ## Usage
16
+
17
+ Configure your VagrantFile with the `ansibleLocal` provisioner:
18
+
19
+ config.vm.provision :ansibleLocal, :playbook => "ansible/ansible.yml"
20
+
21
+ You can run ansible as the vagrant user (rather than as root) by setting `privileged` to false:
22
+
23
+ config.vm.provision :ansibleLocal, :playbook => "ansible/ansible.yml", :privileged => false
24
+
25
+ In case your ansible version is between 1.5 and 1.8 and you are running into an error message saying `ERROR: provided hosts list is empty`, you can either add anything to your `/etc/ansible/hosts` file or change the configuration of the provisioner:
26
+
27
+ config.vm.provision :ansibleLocal, :playbook => "playbooks/playbook.yml", :raw_arguments => "-i 'localhost,'"
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+
38
+ ## TODO
39
+
40
+ * cleanup parameters
41
+ * auto build or mount `inventory-file` and prevent issue with non executable file mounted with 777
42
+ * 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 :privileged
11
+ attr_accessor :sudo
12
+ attr_accessor :sudo_user
13
+ attr_accessor :verbose
14
+ attr_accessor :tags
15
+ attr_accessor :skip_tags
16
+ attr_accessor :start_at_task
17
+ attr_accessor :host_key_checking
18
+
19
+ # Joker attribute, used to pass unsupported arguments to ansible anyway
20
+ attr_accessor :raw_arguments
21
+
22
+ def initialize
23
+ super
24
+
25
+ @playbook = UNSET_VALUE
26
+ @guest_folder = UNSET_VALUE
27
+ @extra_vars = UNSET_VALUE
28
+ @inventory_path = UNSET_VALUE
29
+ @ask_sudo_pass = UNSET_VALUE
30
+ @limit = UNSET_VALUE
31
+ @privileged = UNSET_VALUE
32
+ @sudo = UNSET_VALUE
33
+ @sudo_user = UNSET_VALUE
34
+ @verbose = UNSET_VALUE
35
+ @tags = UNSET_VALUE
36
+ @skip_tags = UNSET_VALUE
37
+ @start_at_task = UNSET_VALUE
38
+ @raw_arguments = UNSET_VALUE
39
+ @host_key_checking = "true"
40
+ end
41
+
42
+ def finalize!
43
+ super
44
+
45
+ @playbook = nil if @playbook == UNSET_VALUE
46
+ @guest_folder = "/tmp/vagrant-ansible-local" if @guest_folder == UNSET_VALUE
47
+ @extra_vars = nil if @extra_vars == UNSET_VALUE
48
+ @inventory_path = nil if @inventory_path == UNSET_VALUE
49
+ @ask_sudo_pass = nil if @ask_sudo_pass == UNSET_VALUE
50
+ @limit = nil if @limit == UNSET_VALUE
51
+ @privileged = nil if @privileged == UNSET_VALUE
52
+ @sudo = nil if @sudo == UNSET_VALUE
53
+ @sudo_user = nil if @sudo_user == UNSET_VALUE
54
+ @verbose = nil if @verbose == UNSET_VALUE
55
+ @tags = nil if @tags == UNSET_VALUE
56
+ @skip_tags = nil if @skip_tags == UNSET_VALUE
57
+ @start_at_task = nil if @start_at_task == UNSET_VALUE
58
+ @raw_arguments = nil if @raw_arguments == UNSET_VALUE
59
+ @host_key_checking = nil if @host_key_checking == UNSET_VALUE
60
+
61
+ if @extra_vars && @extra_vars.is_a?(Hash)
62
+ @extra_vars.each do |k, v|
63
+ @extra_vars[k] = v.to_s
64
+ end
65
+ end
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,85 @@
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
+ # Execute it with sudo
60
+ comm.execute(command, sudo: config.privileged) do |type, data|
61
+ if [:stderr, :stdout].include?(type)
62
+ @machine.env.ui.info(data, :new_line => false, :prefix => false)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ protected
69
+
70
+ def get_verbosity_argument
71
+ if config.verbose.to_s =~ /^v+$/
72
+ # ansible-playbook accepts "silly" arguments like '-vvvvv' as '-vvvv' for now
73
+ return "-#{config.verbose}"
74
+ else
75
+ # safe default, in case input strays
76
+ return '-v'
77
+ end
78
+ end
79
+
80
+ def as_list_argument(v)
81
+ v.kind_of?(Array) ? v.join(',') : v
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module AnsibleLocal
3
+ VERSION = "0.0.3"
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-privileged"
8
+ spec.version = Vagrant::AnsibleLocal::VERSION
9
+ spec.authors = ["kfr2"]
10
+ spec.email = ["kevin.f.richardson@gmail.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,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ansible-local-privileged
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - kfr2
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: '"vagrant plugin to provision VM with ansible in local mode"'
42
+ email:
43
+ - kevin.f.richardson@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - lib/vagrant-ansible-local.rb
55
+ - lib/vagrant-ansible-local/config.rb
56
+ - lib/vagrant-ansible-local/plugin.rb
57
+ - lib/vagrant-ansible-local/provisioner.rb
58
+ - lib/vagrant-ansible-local/version.rb
59
+ - vagrant-ansible-local.gemspec
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: '"vagrant plugin to provision VM with ansible in local mode"'
84
+ test_files: []