vagrant-puppetconf 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -38,6 +38,14 @@ Example Vagrant file:
38
38
  config.puppetconf.updates = {'main/environment' => 'test'} # Set environment to test
39
39
  end
40
40
 
41
+ Additional commands:
42
+
43
+ Updates and puppet.conf config on the fly.
44
+ vagrant puppetconf -k main/environment -v test
45
+
46
+ Update puppet.conf environment config on the fly.
47
+ vagrant puppetenv test
48
+
41
49
  ## Contributing
42
50
 
43
51
  1. Fork it
@@ -0,0 +1,42 @@
1
+ module VagrantPuppetconf
2
+ module Command
3
+
4
+ class Puppetconf < Vagrant::Command::Base
5
+
6
+ def validate(options)
7
+ %w{key value}.each do |opt|
8
+ if options[opt.to_sym].empty?
9
+ @ui.error "#{opt.upcase} not set"
10
+ @ui.info "#{@opts}"
11
+ exit 1
12
+ end
13
+ end
14
+ end
15
+
16
+ def execute
17
+ @ui = Vagrant::UI::Colored.new('puppetconf')
18
+
19
+ options = {}
20
+ @opts = OptionParser.new do |opts|
21
+ opts.banner = "Usage: vagrant [vm-name] puppetconf -k config_key -v config_value"
22
+
23
+ opts.on('-k', '--key CONFIG_KEY', I18n.t('vagrant.plugins.puppetconf.command.options.key')) do |val|
24
+ options[:key] = val
25
+ end
26
+
27
+ opts.on('-v', '--value CONFIG_VALUE', I18n.t('vagrant.plugins.puppetconf.command.options.value')) do |val|
28
+ options[:value] = val
29
+ end
30
+ end
31
+
32
+ vms = parse_options @opts
33
+
34
+ validate options
35
+
36
+ with_target_vms(vms) do |vm|
37
+ Updater.update(vm, @ui, {options[:key] => options[:value]})
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+
2
+ module VagrantPuppetconf
3
+ module Command
4
+
5
+ class Puppetenv < Vagrant::Command::Base
6
+
7
+ def validate(options)
8
+ %w{environment}.each do |opt|
9
+ if options[opt.to_sym].nil? || options[opt.to_sym].empty?
10
+ @ui.error "#{opt.upcase} not set"
11
+ @ui.info "Usage: vagrant [vm-name] puppetenv #{I18n.t('vagrant.plugins.puppetconf.command.options.environment')}"
12
+ exit 1
13
+ end
14
+ end
15
+ end
16
+
17
+ def execute
18
+ @ui = Vagrant::UI::Colored.new('puppetconf')
19
+ options = {}
20
+
21
+ argv = parse_options OptionParser.new
22
+ args = split_main_and_subcommand argv
23
+
24
+ vms = args[0]
25
+ options[:environment] = args[1]
26
+
27
+ validate options
28
+
29
+ with_target_vms(vms) do |vm|
30
+ Updater.update(vm, @ui, {'main/environment' => options[:environment]})
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -9,28 +9,10 @@ module VagrantPuppetconf
9
9
  @env = env
10
10
  create_puppet_conf unless puppet_conf_exists?
11
11
  install_augeas unless augeas_installed?
12
- update
12
+ Updater.update(@env[:vm], @env[:ui], @env[:vm].config.puppetconf.updates, @env[:vm].config.puppetconf.update_only)
13
13
  @app.call env
14
14
  end
15
15
 
16
- def update
17
- @env[:vm].channel.sudo("rm -f /etc/puppet/puppet.conf.augsave")
18
- unless @env[:vm].config.puppetconf.update_only
19
- @env[:vm].channel.sudo("cp /dev/null /etc/puppet/puppet.conf")
20
- end
21
- aug_commands = []
22
- @env[:vm].config.puppetconf.updates.each_pair do |path, value|
23
- aug_commands << "set /files/etc/puppet/puppet.conf/#{path} #{value}"
24
- end
25
- @env[:vm].channel.execute("echo -e \"#{aug_commands.join("\n")} \n save\" | sudo augtool -b")
26
- if @env[:vm].channel.execute("ls /etc/puppet/puppet.conf.augsave")
27
- @env[:ui].info I18n.t('vagrant.plugins.puppetconf.middleware.puppetconf_diff')
28
- @env[:vm].channel.execute('diff -u /etc/puppet/puppet.conf /etc/puppet/puppet.conf.augsave', :error_check => false) do |type, data|
29
- @env[:ui].success data, :prefix => false
30
- end
31
- end
32
- end
33
-
34
16
  def puppet_conf_exists?
35
17
  @env[:vm].channel.execute("ls /etc/puppet/puppet.conf", :error_check => false) == 0
36
18
  end
@@ -0,0 +1,23 @@
1
+ module VagrantPuppetconf
2
+
3
+ class Updater
4
+
5
+ def self.update(vm, logger, updates, update_only = true)
6
+ vm.channel.sudo("rm -f /etc/puppet/puppet.conf.augsave")
7
+ vm.channel.sudo("cp /dev/null /etc/puppet/puppet.conf") unless update_only
8
+ aug_commands = []
9
+ updates.each_pair do |path, value|
10
+ aug_commands << "set /files/etc/puppet/puppet.conf/#{path} #{value}"
11
+ end
12
+ vm.channel.execute("echo -e \"#{aug_commands.join("\n")} \n save\" | sudo augtool -b")
13
+ if vm.channel.execute("ls /etc/puppet/puppet.conf.augsave", :error_check => false) == 0
14
+ logger.info I18n.t('vagrant.plugins.puppetconf.updater.puppetconf_diff')
15
+ vm.channel.execute('diff -u /etc/puppet/puppet.conf.augsave /etc/puppet/puppet.conf', :error_check => false) do |type, data|
16
+ logger.success data, :prefix => false
17
+ end
18
+ else
19
+ logger.warn I18n.t('vagrant.plugins.puppetconf.updater.puppetconf_nochange')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Puppetconf
3
- VERSION = "0.1.5"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -1,7 +1,13 @@
1
1
  require 'vagrant'
2
+ require 'vagrant-puppetconf/updater'
3
+ require 'vagrant-puppetconf/command/puppetconf'
4
+ require 'vagrant-puppetconf/command/puppetenv'
2
5
  require 'vagrant-puppetconf/middleware'
3
6
  require 'vagrant-puppetconf/config'
4
7
 
8
+ Vagrant.commands.register(:puppetconf) { VagrantPuppetconf::Command::Puppetconf }
9
+ Vagrant.commands.register(:puppetenv) { VagrantPuppetconf::Command::Puppetenv }
10
+
5
11
  Vagrant.config_keys.register(:puppetconf) { VagrantPuppetconf::Config }
6
12
 
7
13
  Vagrant.actions[:start].use VagrantPuppetconf::Middleware
data/locales/en.yml CHANGED
@@ -2,7 +2,14 @@ en:
2
2
  vagrant:
3
3
  plugins:
4
4
  puppetconf:
5
+ command:
6
+ options:
7
+ key: "Config key to update."
8
+ value: "Value to set"
9
+ environment: "ENVIRONMENT"
5
10
  middleware:
6
11
  create_puppetconf: "Creating puppet.conf"
7
12
  install_augeas: "Installing augeas-tools"
13
+ updater:
8
14
  puppetconf_diff: "diff puppet.conf:"
15
+ puppetconf_nochange: "No change to puppet.conf"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-puppetconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant
@@ -39,8 +39,11 @@ files:
39
39
  - README.md
40
40
  - Rakefile
41
41
  - lib/vagrant-puppetconf.rb
42
+ - lib/vagrant-puppetconf/command/puppetconf.rb
43
+ - lib/vagrant-puppetconf/command/puppetenv.rb
42
44
  - lib/vagrant-puppetconf/config.rb
43
45
  - lib/vagrant-puppetconf/middleware.rb
46
+ - lib/vagrant-puppetconf/updater.rb
44
47
  - lib/vagrant-puppetconf/version.rb
45
48
  - lib/vagrant_init.rb
46
49
  - locales/en.yml