Last active
October 3, 2016 16:07
-
-
Save daften/ff54d05dd6dafc4f2d3048be8bb6fdec to your computer and use it in GitHub Desktop.
Guards for chef with or
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chef::Log.info(shell_out("#{node['composer']['bin']} show #{package} #{new_resource.version}").exitstatus) | |
execute 'Install-composer-for-single-project' do | |
cwd new_resource.project_dir | |
command "#{node['composer']['bin']} require #{package}:#{new_resource.version} #{dev} #{prefer_dist}" | |
environment ({ | |
'COMPOSER_HOME' => Composer.home_dir(node), | |
'COMPOSER_BIN_DIR' => new_resource.bin_dir | |
}) | |
action :run | |
not_if do | |
shell_out("#{node['composer']['bin']} show #{package} #{new_resource.version}").exitstatus == 0 | |
end | |
user new_resource.user | |
group new_resource.group | |
umask new_resource.umask | |
end |
are you saying you need to change directory for your guard clause as well as the actual 'command'?
It now looks like this (the guard):
not_if do
!new_resource.version.include?('*') &&
shell_out("cd #{new_resource.project_dir} && #{node['composer']['bin']} show #{package} #{new_resource.version}").exitstatus == 0
end
Thanks for the help
And yes, i needed to change dir for both :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't get it to work with shell_out, can't figure out how exactly to use it, to get the exitcode. I can't find any examples on how to use it in this context online, and chef with debug enabled doesn't give much output either to go on.