I am currently running Chef Test Kitchen, which spins up an Amazon Linux 2 EC2 instances and converges 2 recipes from a Chef cookbook. The strange thing is that my coworkers do not seem to be facing the same issue when converging(despite the cookbook being exactly the same and using the same kitchen configuration to spin up the host.
Basically, it is giving me an error at this chef action.
cookbook_file "#{bamboo_user_home_dir}/import-rds-certs.sh" do
source "server/scripts/import-rds-certs.sh"
owner bamboo_user
group bamboo_user
mode 0700
end
Here is the kitchen converge error output:
STDERR:
/home/bamboo/.bash_profile: line 21: rbenv: command not found
: No such file or directory
---- End output of su - bamboo -c "/home/bamboo/import-rds-certs.sh >> /home/bamboo/import-rds-certs.log" ----
Ran su - bamboo -c "/home/bamboo/import-rds-certs.sh >> /home/bamboo/import-rds-certs.log" returned 127`
It seems when switching to bamboo user, it is running the login script .bash_profile and unable to find the rbenv command. Below is the relevant part of the script that appears to be failing.
export PATH="${HOME}/.rbenv/bin:${M2_HOME}/bin:${JAVA_HOME}/bin:${JAVA6EE_HOME}/bin:${TOOLS_DIR}/bin:${NODE_HOME}/bin:${PATH}:${HOME}/bin:${HOME}/.rvm/bin:${FIREFOX_HOME}:${CHEF_LOCAL_GEM_HOME}"
eval "$(rbenv init -)"
When I SSH into the host, and try to pull the rbenv package manually, it says that no such package exists in any repositories.
Furthermore, the recipe does pull the rbenv package further down the file, but way after the chef resource that fails that was previously mentioned, so I don't even think it is running this action.
remote_file "#{bamboo_downloads_dir}/rbenv-master.tar.gz" do
source "#{v4dcm_artifactory_url}/third-party-local/bamboo/rbenv-master.tar.gz"
mode 0775
owner bamboo_user
group bamboo_user
action :create
headers( "Authorization"=>"Basic #{ Base64.encode64("#{chef_artifactory_user}:#{chef_artifactory_user_api_key}").gsub("\n", "") }" )
sensitive true
notifies :run, "execute[untar-rbenv-master]", :immediately
end
So am I wrong when I say, is it failing because it is running a login script that requires rbenv, before Chef made the action to pull the rbenv file?
If this is the case, why are my coworkers not experiencing this error? In fact, this cookbook has been working fine in the past and my coworkers host has rbenv downloaded.