Using not_if in bash block still causes file to be downloaded


#1

Hello everyone,

I’m writing a recipe to install hubot using the bash resource and using the
not_if constraint to avoid reinstalling each time chef-client runs. While
the reinstall does not happen, I’m finding that the hubot file continues to
be downloaded with wget. Therefore, the /tmp dir is filling up with hubot
tar files. Is there a reason why parts of the bash block execute and others
don’t?

The recipe looks as follows:

install_dir = "#{node[‘hubot’][‘install_dir’]}"
install_dir_parent = "#{node[‘hubot’][‘install_dir_parent’]}"
version = “#{node[‘hubot’][‘version’]}”

bash “install hubot” do
user hubot_user
group hubot_group
environment ({‘HOME’ => “#{install_dir}” })
cwd install_dir_parent
code <<-EOH
wget -P /tmp
https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz &&
tar xzf /tmp/hubot-#{version}.tar.gz &&
cd hubot &&
npm install
EOH
not_if "#{install_dir}/bin/hubot -v 2>&1 | grep ‘#{version}’"
end

The full recipe file is here: https://gist.github.com/1730793. Thank you in
advance for any help.

All the best,

Arthur Kalmenson


#2

Perhaps using remote_file might be cleaner?

remote_file “/tmp/hubot-#{version}.tar.gz” do
source "https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz"
action :create_if_missing
end

execute “tar -xzf /tmp/hubot-#{version}.tar.gz” do
cwd “/tmp"
subscribes :run, resources(:remote_file =>
”/tmp/hubot-#{version}.tar.gz"), :immediately
action :nothing
end

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray

On Fri, Feb 3, 2012 at 9:43 AM, Arthur Kalmenson arthur.kalm@gmail.com wrote:

Hello everyone,

I’m writing a recipe to install hubot using the bash resource and using the
not_if constraint to avoid reinstalling each time chef-client runs. While
the reinstall does not happen, I’m finding that the hubot file continues to
be downloaded with wget. Therefore, the /tmp dir is filling up with hubot
tar files. Is there a reason why parts of the bash block execute and others
don’t?

The recipe looks as follows:

install_dir = "#{node[‘hubot’][‘install_dir’]}"
install_dir_parent = "#{node[‘hubot’][‘install_dir_parent’]}"
version = “#{node[‘hubot’][‘version’]}”

bash “install hubot” do
user hubot_user
group hubot_group
environment ({‘HOME’ => “#{install_dir}” })
cwd install_dir_parent
code <<-EOH
wget -P /tmp
https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz &&
tar xzf /tmp/hubot-#{version}.tar.gz &&
cd hubot &&
npm install
EOH
not_if "#{install_dir}/bin/hubot -v 2>&1 | grep ‘#{version}’"
end

The full recipe file is here: https://gist.github.com/1730793. Thank you in
advance for any help.

All the best,

Arthur Kalmenson


#3

Thanks Matt, that worked perfectly.


Arthur Kalmenson

On Fri, Feb 3, 2012 at 11:11 AM, Matt Ray matt@opscode.com wrote:

Perhaps using remote_file might be cleaner?

remote_file “/tmp/hubot-#{version}.tar.gz” do
source "
https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz"
action :create_if_missing
end

execute “tar -xzf /tmp/hubot-#{version}.tar.gz” do
cwd “/tmp"
subscribes :run, resources(:remote_file =>
”/tmp/hubot-#{version}.tar.gz"), :immediately
action :nothing
end

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray

On Fri, Feb 3, 2012 at 9:43 AM, Arthur Kalmenson arthur.kalm@gmail.com
wrote:

Hello everyone,

I’m writing a recipe to install hubot using the bash resource and using
the
not_if constraint to avoid reinstalling each time chef-client runs. While
the reinstall does not happen, I’m finding that the hubot file continues
to
be downloaded with wget. Therefore, the /tmp dir is filling up with hubot
tar files. Is there a reason why parts of the bash block execute and
others
don’t?

The recipe looks as follows:

install_dir = "#{node[‘hubot’][‘install_dir’]}"
install_dir_parent = "#{node[‘hubot’][‘install_dir_parent’]}"
version = “#{node[‘hubot’][‘version’]}”

bash “install hubot” do
user hubot_user
group hubot_group
environment ({‘HOME’ => “#{install_dir}” })
cwd install_dir_parent
code <<-EOH
wget -P /tmp
https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz &&
tar xzf /tmp/hubot-#{version}.tar.gz &&
cd hubot &&
npm install
EOH
not_if "#{install_dir}/bin/hubot -v 2>&1 | grep ‘#{version}’"
end

The full recipe file is here: https://gist.github.com/1730793. Thank
you in
advance for any help.

All the best,

Arthur Kalmenson


#4

On Friday, February 3, 2012 at 1:01 PM, Arthur Kalmenson wrote:

Thanks Matt, that worked perfectly.


Arthur Kalmenson

On Fri, Feb 3, 2012 at 11:11 AM, Matt Ray <matt@opscode.com (mailto:matt@opscode.com)> wrote:

Perhaps using remote_file might be cleaner?

On Fri, Feb 3, 2012 at 9:43 AM, Arthur Kalmenson <arthur.kalm@gmail.com (mailto:arthur.kalm@gmail.com)> wrote:

Hello everyone,

I’m writing a recipe to install hubot using the bash resource and using the
not_if constraint to avoid reinstalling each time chef-client runs. While
the reinstall does not happen, I’m finding that the hubot file continues to
be downloaded with wget. Therefore, the /tmp dir is filling up with hubot
tar files. Is there a reason why parts of the bash block execute and others
don’t?

The recipe looks as follows:

bash “install hubot” do
user hubot_user
group hubot_group
environment ({‘HOME’ => “#{install_dir}” })
cwd install_dir_parent
code <<-EOH
wget -P /tmp
https://github.com/downloads/github/hubot/hubot-#{version}.tar.gz &&
tar xzf /tmp/hubot-#{version}.tar.gz &&
cd hubot &&
npm install
EOH
not_if "#{install_dir}/bin/hubot -v 2>&1 | grep ‘#{version}’"
end

The full recipe file is here: https://gist.github.com/1730793. Thank you in
advance for any help.

All the best,

Arthur Kalmenson

Remote file is definitely the way to go for operations like this. But I’m confused as to why the not_if didn’t work. Is it possible that you had the version in the install_dir? Also, the latest version of Chef allows multiple not_if statements, so you could test that the hubot command exists and then test that it’s the correct version.

HTH,
Dan DeLeo