From 8f9a5671de0475a479c090d6e7d468f44c665dee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Apr 2013 13:09:52 -0700 Subject: [PATCH] Support installing CFEngine on RedHat --- .../cfengine/cap/redhat/cfengine_install.rb | 24 +++++++++++++++++++ plugins/provisioners/cfengine/config.rb | 18 +++++++++++--- plugins/provisioners/cfengine/plugin.rb | 5 ++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 plugins/provisioners/cfengine/cap/redhat/cfengine_install.rb diff --git a/plugins/provisioners/cfengine/cap/redhat/cfengine_install.rb b/plugins/provisioners/cfengine/cap/redhat/cfengine_install.rb new file mode 100644 index 000000000..820886f4d --- /dev/null +++ b/plugins/provisioners/cfengine/cap/redhat/cfengine_install.rb @@ -0,0 +1,24 @@ +require "log4r" + +module VagrantPlugins + module CFEngine + module Cap + module RedHat + module CFEngineInstall + def self.cfengine_install(machine, config) + logger = Log4r::Logger.new("vagrant::plugins::cfengine::cap_redhat_cfengine_install") + + machine.communicate.tap do |comm| + logger.info("Adding the CFEngine repository to #{config.yum_repo_file}") + comm.sudo("mkdir -p #{File.dirname(config.yum_repo_file)} && (echo '[cfengine-repository]'; echo 'name=CFEngine Community Yum Repository'; echo 'baseurl=#{config.yum_repo_url}'; echo 'enabled=1'; echo 'gpgcheck=1') > #{config.yum_repo_file}") + logger.info("Installing CFEngine Community Yum Repository GPG KEY from #{config.repo_gpg_key_url}") + comm.sudo("GPGFILE=$(mktemp) && wget -O $GPGFILE #{config.repo_gpg_key_url} && rpm --import $GPGFILE; rm -f $GPGFILE") + + comm.sudo("yum -y install cfengine-community") + end + end + end + end + end + end +end diff --git a/plugins/provisioners/cfengine/config.rb b/plugins/provisioners/cfengine/config.rb index 6257f1bca..b3372bc77 100644 --- a/plugins/provisioners/cfengine/config.rb +++ b/plugins/provisioners/cfengine/config.rb @@ -7,12 +7,16 @@ module VagrantPlugins attr_accessor :deb_repo_file attr_accessor :deb_repo_line attr_accessor :repo_gpg_key_url + attr_accessor :yum_repo_file + attr_accessor :yum_repo_url def initialize - @deb_repo_file = UNSET_VALUE - @deb_repo_line = UNSET_VALUE - @install = UNSET_VALUE + @deb_repo_file = UNSET_VALUE + @deb_repo_line = UNSET_VALUE + @install = UNSET_VALUE @repo_gpg_key_url = UNSET_VALUE + @yum_repo_file = UNSET_VALUE + @yum_repo_url = UNSET_VALUE end def finalize! @@ -30,6 +34,14 @@ module VagrantPlugins if @repo_gpg_key_url == UNSET_VALUE @repo_gpg_key_url = "http://cfengine.com/pub/gpg.key" end + + if @yum_repo_file == UNSET_VALUE + @yum_repo_file = "/etc/yum.repos.d/cfengine-community.repo" + end + + if @yum_repo_url == UNSET_VALUE + @yum_repo_url = "http://cfengine.com/pub/yum/" + end end end end diff --git a/plugins/provisioners/cfengine/plugin.rb b/plugins/provisioners/cfengine/plugin.rb index 8e5a21609..d54985a72 100644 --- a/plugins/provisioners/cfengine/plugin.rb +++ b/plugins/provisioners/cfengine/plugin.rb @@ -23,6 +23,11 @@ module VagrantPlugins Cap::Linux::CFEngineInstalled end + guest_capability("redhat", "cfengine_install") do + require_relative "cap/redhat/cfengine_install" + Cap::RedHat::CFEngineInstall + end + provisioner(:cfengine) do require_relative "provisioner" Provisioner