Class: VagrantHiera::Middleware::Setup
- Inherits:
-
Object
- Object
- VagrantHiera::Middleware::Setup
- Defined in:
- lib/vagrant-hiera/middleware/setup.rb
Constant Summary collapse
- APT_SOURCE_FILE =
'/etc/apt/sources.list.d/puppetlabs.list'
Instance Method Summary collapse
- #add_apt_repo ⇒ Object
- #apt_repo_set? ⇒ Boolean
- #call(env) ⇒ Object
- #create_shared_folders ⇒ Object
- #create_symlink_to_hiera_config ⇒ Object
- #hiera_installed? ⇒ Boolean
- #hiera_puppet_installed? ⇒ Boolean
-
#initialize(app, env) ⇒ Setup
constructor
A new instance of Setup.
- #install_hiera ⇒ Object
- #install_hiera_puppet ⇒ Object
- #install_puppet ⇒ Object
- #puppet_installed? ⇒ Boolean
Constructor Details
#initialize(app, env) ⇒ Setup
Returns a new instance of Setup.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 7 def initialize(app, env) @app = app @env = env @guest_config_path = @env[:vm].config.hiera.guest_config_path @guest_data_path = @env[:vm].config.hiera.guest_data_path @config_path = @env[:vm].config.hiera.config_path @data_path = @env[:vm].config.hiera.data_path @config_file = @env[:vm].config.hiera.config_file @puppet_version = @env[:vm].config.hiera.puppet_version @puppet_apt_source = @env[:vm].config.hiera.puppet_apt_source @apt_opts = @env[:vm].config.hiera.apt_opts @hiera_puppet_version = @env[:vm].config.hiera.hiera_puppet_version @hiera_version = @env[:vm].config.hiera.hiera_version end |
Instance Method Details
#add_apt_repo ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 45 def add_apt_repo @env[:ui].warn I18n.t('vagrant.plugins.hiera.middleware.setup.add_apt_repo') @env[:vm].channel.sudo("wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb") @env[:vm].channel.sudo("dpkg -i puppetlabs-release-stable.deb") @env[:vm].channel.sudo("echo '#{@puppet_apt_source}' >> #{APT_SOURCE_FILE}") @env[:vm].channel.sudo("apt-get update") end |
#apt_repo_set? ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 38 def apt_repo_set? cmd = "test -f #{APT_SOURCE_FILE} && grep '#{@puppet_apt_source}' #{APT_SOURCE_FILE}" setup = ( @env[:vm].channel.execute(cmd, :error_check => false) == 0 ) @env[:ui].success I18n.t('vagrant.plugins.hiera.middleware.setup.apt_repo_set') if setup setup end |
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 23 def call(env) @env = env if @env[:vm].config.hiera.set? add_apt_repo unless apt_repo_set? install_puppet unless puppet_installed? install_hiera unless hiera_installed? if @env[:vm].config.hiera.install_puppet_heira? install_hiera_puppet unless hiera_puppet_installed? end create_shared_folders create_symlink_to_hiera_config end @app.call(env) end |
#create_shared_folders ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 87 def create_shared_folders @env[:ui].info I18n.t('vagrant.plugins.hiera.middleware.setup.shared_folders') data = {} data[:owner] ||= @env[:vm].config.ssh.username data[:group] ||= @env[:vm].config.ssh.username @env[:vm].guest.mount_shared_folder('vagrant-hiera-config', @guest_config_path, data) @env[:vm].guest.mount_shared_folder('vagrant-hiera-data', @guest_data_path, data) end |
#create_symlink_to_hiera_config ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 96 def create_symlink_to_hiera_config @env[:ui].info I18n.t('vagrant.plugins.hiera.middleware.setup.installing_hiera_config') @env[:vm].channel.sudo("mkdir -p /etc/puppet") # This is where I think this file will end up once the official puppet v3 release is out @env[:vm].channel.sudo("ln -fs #{@guest_config_path}/#{@config_file} /etc/hiera.yaml") # But this is where it looks for it now @env[:vm].channel.sudo("ln -fs #{@guest_config_path}/#{@config_file} /etc/puppet/hiera.yaml") end |
#hiera_installed? ⇒ Boolean
53 54 55 56 57 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 53 def hiera_installed? installed = ( @env[:vm].channel.execute("dpkg -l | grep puppet | grep #{@puppet_version}", :error_check => false) == 0 ) @env[:ui].success I18n.t('vagrant.plugins.hiera.middleware.setup.hiera_installed') if installed installed end |
#hiera_puppet_installed? ⇒ Boolean
76 77 78 79 80 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 76 def hiera_puppet_installed? installed = ( @env[:vm].channel.execute("dpkg -l | grep hiera-puppet | grep #{@hiera_puppet_version}", :error_check => false) == 0 ) @env[:ui].success I18n.t('vagrant.plugins.hiera.middleware.setup.hiera_puppet_installed') if installed installed end |
#install_hiera ⇒ Object
59 60 61 62 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 59 def install_hiera @env[:ui].warn I18n.t('vagrant.plugins.hiera.middleware.setup.install_hiera') @env[:vm].channel.sudo("apt-get #{@apt_opts} install hiera=#{@hiera_version}") end |
#install_hiera_puppet ⇒ Object
82 83 84 85 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 82 def install_hiera_puppet @env[:ui].warn I18n.t('vagrant.plugins.hiera.middleware.setup.install_hiera_puppet') @env[:vm].channel.sudo("apt-get #{@apt_opts} install hiera-puppet=#{@hiera_puppet_version}") end |
#install_puppet ⇒ Object
70 71 72 73 74 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 70 def install_puppet @env[:ui].warn I18n.t('vagrant.plugins.hiera.middleware.setup.install_puppet') @env[:vm].channel.sudo("apt-get #{@apt_opts} install puppet-common=#{@puppet_version}") @env[:vm].channel.sudo("apt-get #{@apt_opts} install puppet=#{@puppet_version}") end |
#puppet_installed? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/vagrant-hiera/middleware/setup.rb', line 64 def puppet_installed? installed = ( @env[:vm].channel.execute("dpkg -l | grep puppet | grep #{@puppet_version}", :error_check => false) == 0 ) @env[:ui].success I18n.t('vagrant.plugins.hiera.middleware.setup.puppet_installed') if installed installed end |