From 30f4eb62eac2e3bada457d485b6f569d1e28b0fb Mon Sep 17 00:00:00 2001 From: Anand Suresh Date: Tue, 4 Apr 2017 22:10:02 -0700 Subject: [PATCH] Add chef_install(ed?) guest capability for freebsd --- .../chef/cap/freebsd/chef_install.rb | 18 +++++++++++++++ .../chef/cap/freebsd/chef_installed.rb | 22 +++++++++++++++++++ plugins/provisioners/chef/plugin.rb | 10 +++++++++ 3 files changed, 50 insertions(+) create mode 100644 plugins/provisioners/chef/cap/freebsd/chef_install.rb create mode 100644 plugins/provisioners/chef/cap/freebsd/chef_installed.rb diff --git a/plugins/provisioners/chef/cap/freebsd/chef_install.rb b/plugins/provisioners/chef/cap/freebsd/chef_install.rb new file mode 100644 index 000000000..d763f44c6 --- /dev/null +++ b/plugins/provisioners/chef/cap/freebsd/chef_install.rb @@ -0,0 +1,18 @@ +require_relative "../../omnibus" + +module VagrantPlugins + module Chef + module Cap + module FreeBSD + module ChefInstall + def self.chef_install(machine, project, version, channel, options = {}) + machine.communicate.sudo("pkg install -y -qq curl bash") + + command = Omnibus.sh_command(project, version, channel, options) + machine.communicate.sudo(command) + end + end + end + end + end +end diff --git a/plugins/provisioners/chef/cap/freebsd/chef_installed.rb b/plugins/provisioners/chef/cap/freebsd/chef_installed.rb new file mode 100644 index 000000000..bb58083ca --- /dev/null +++ b/plugins/provisioners/chef/cap/freebsd/chef_installed.rb @@ -0,0 +1,22 @@ +module VagrantPlugins + module Chef + module Cap + module FreeBSD + module ChefInstalled + # Check if Chef is installed at the given version. + # @return [true, false] + def self.chef_installed(machine, product, version) + knife = "/opt/#{product}/bin/knife" + command = "test -x #{knife}" + + if version != :latest + command << "&& #{knife} --version | grep 'Chef: #{version}'" + end + + machine.communicate.test(command, sudo: true) + end + end + end + end + end +end diff --git a/plugins/provisioners/chef/plugin.rb b/plugins/provisioners/chef/plugin.rb index 48a51e031..26bbf1a32 100644 --- a/plugins/provisioners/chef/plugin.rb +++ b/plugins/provisioners/chef/plugin.rb @@ -58,6 +58,16 @@ module VagrantPlugins Cap::Debian::ChefInstall end + guest_capability(:freebsd, :chef_install) do + require_relative "cap/freebsd/chef_install" + Cap::FreeBSD::ChefInstall + end + + guest_capability(:freebsd, :chef_installed) do + require_relative "cap/freebsd/chef_installed" + Cap::FreeBSD::ChefInstalled + end + guest_capability(:linux, :chef_installed) do require_relative "cap/linux/chef_installed" Cap::Linux::ChefInstalled