Chef Notify Before?


#1

Hi,

I’m just working on a recipe and what I’d like to be able to do is if a package isn’t installed it should go and get the required files before running, something like:

windows_batch “unzip_vs2010” do

code <<-EOH

“#{zippath}” x “#{vs2010_iso_location}” -o#{vs2010_extraction_path} -r -y

EOH

action: nothing

end

windows_package “#{node[‘vs-2010’][‘base-display-name’] }” do
source "#{vs2010setup}"
options "/q /norestart /unattendfile “#{unattendini}”"
installer_type :custom
action :install

notifies :run, ‘windows_batch[unzip_vs2010]’, :before
end

Is there an easy way to do this?

Thanks

Dan

===================== DISCLAIMER ======================
This message is intended only for the use of the person(s)
(“Intended Recipient”) to whom it is addressed. It may contain
information which is privileged and confidential. Accordingly
any dissemination, distribution, copying or other use of this
message or any of its content by any person other than the Intended
Recipient may constitute a breach of civil or criminal law and is
strictly prohibited. If you are not the Intended Recipient, please
contact the sender as soon as possible.

Reed Business Information Limited.
Registered Office: Quadrant House, The Quadrant, Sutton, Surrey, SM2 5AS, UK.
Registered in England under Company No. 151537

=======================================================


#2

not directly . In chef resource are executed in the same order as you
specify them. Given you want the package and the package depends on the
file, you should specify the file resource just before the package. What is
important is your file resource is idempotent. That will make the entire
recipe way more simpler and readable, i.e. windows_batch “vs_20120” should
have action create, but also a decent not_if/only_if guard so that it does
not get executed directly.

On Wed, Mar 13, 2013 at 5:03 AM, Gibbons, Daniel (RBI-UK) <
Daniel.Gibbons@rbi.co.uk> wrote:

Hi,****


I’m just working on a recipe and what I’d like to be able to do is if a
package isn’t installed it should go and get the required files before
running, something like:****


windows_batch “unzip_vs2010” do****

code <<-EOH****

“#{zippath}” x “#{vs2010_iso_location}” -o#{vs2010_extraction_path} -r -y****

EOH****

action: nothing****

end****


windows_package “#{node[‘vs-2010’][‘base-display-name’] }” do****

source “#{vs2010setup}”****

options “/q /norestart /unattendfile “#{unattendini}””****

installer_type :custom****

action :install****

  • notifies :run, ‘windows_batch[unzip_vs2010]’, :before*

end****


Is there an easy way to do this?****


Thanks****


Dan****


===================== DISCLAIMER ======================
This message is intended only for the use of the person(s)
(“Intended Recipient”) to whom it is addressed. It may contain
information which is privileged and confidential. Accordingly
any dissemination, distribution, copying or other use of this
message or any of its content by any person other than the Intended
Recipient may constitute a breach of civil or criminal law and is
strictly prohibited. If you are not the Intended Recipient, please
contact the sender as soon as possible.

Reed Business Information Limited.
Registered Office: Quadrant House, The Quadrant, Sutton, Surrey, SM2 5AS,
UK.
Registered in England under Company No. 151537

=======================================================


#3

Hi,

Under linux I have been using not ifs with procs so that I don’t
download/unpack/install package if they are already isntalled.
SOmething similar to the following. HTH.

package_url = node[‘foo’][‘package_url’]
base_package_filename = File.basename(package_url)
cached_package_filename =
"#{Chef::Config[:file_cache_path]}/#{base_package_filename}"
check_proc = Proc.new { ::File.exists?( node[‘foo’][‘base_dir’] ) }

remote_file cached_package_filename do
not_if { check_proc.call }
source package_url
mode '0600’
action :create_if_missing
end

package ‘unzip’

bash ‘unpack_foo’ do
not_if { check_proc.call }
code <<-EOF

EOF
end

bash ‘install_foo’ do
not_if { check_proc.call }
code <<-EOF

test -d #{node[‘foo’][‘base_dir’]}
EOF
end


Cheers,

Peter Donald


#4

this looks fine,
you can change the remote_file resource guard should be not_if
{::File.exists?(cached_package_name)}.

this should work.

On Wed, Mar 13, 2013 at 3:46 PM, Peter Donald peter@realityforge.orgwrote:

Hi,

Under linux I have been using not ifs with procs so that I don’t
download/unpack/install package if they are already isntalled.
SOmething similar to the following. HTH.

package_url = node[‘foo’][‘package_url’]
base_package_filename = File.basename(package_url)
cached_package_filename =
"#{Chef::Config[:file_cache_path]}/#{base_package_filename}"
check_proc = Proc.new { ::File.exists?( node[‘foo’][‘base_dir’] ) }

remote_file cached_package_filename do
not_if { check_proc.call }
source package_url
mode '0600’
action :create_if_missing
end

package ‘unzip’

bash ‘unpack_foo’ do
not_if { check_proc.call }
code <<-EOF

EOF
end

bash ‘install_foo’ do
not_if { check_proc.call }
code <<-EOF

test -d #{node[‘foo’][‘base_dir’]}
EOF
end


Cheers,

Peter Donald


#5

Hi,

On Thu, Mar 14, 2013 at 11:27 AM, Ranjib Dey dey.ranjib@gmail.com wrote:

this looks fine,
you can change the remote_file resource guard should be not_if
{::File.exists?(cached_package_name)}.

this should work.

You can do that but then chef will download the package file to the
cache even if the service is already installed. This is not usually a
problem except when the cache is cleaned which happens occasionally.
However when we test under vagrant the cache is cleared everytime and
thus this change would result in the package being downloaded for
every test even if service is installed … which can be annoying for
large packages across the interwebs.


Cheers,

Peter Donald