Skip to content

Instantly share code, notes, and snippets.

@MattDevUK
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattDevUK/7d4a7a52775a30706719 to your computer and use it in GitHub Desktop.
Save MattDevUK/7d4a7a52775a30706719 to your computer and use it in GitHub Desktop.
Description of user-data issue for cloud-init
###### User-data script #####
#!/bin/bash
yum install wget -y
wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-12.2.1-1.el6.x86_64.rpm
rpm -ivh chef-12.2.1-1.el6.x86_64.rpm
echo "home is set to '$HOME'"
mkdir -p /etc/chef
# write first-boot.json
(
cat << 'EOP'
{"run_list": ["role[trading]"]}
EOP
) > /etc/chef/first-boot.json
echo "10.0.0.103 chef-server aws-chef.com" >> /etc/hosts
# write client.rb
(
cat << 'EOP'
log_location STDOUT
chef_server_url "https://chef-server:443/"
validation_client_name "chef-validator"
ssl_verify_mode :verify_none
EOP
) > /etc/chef/client.rb
# Bootstrap chef
chef-client -j /etc/chef/first-boot.json -l debug
####################################################################################################################################
###### Part of Chef run that fails #######
bash 'rhel_build_install' do
user 'root'
cwd Chef::Config[:file_cache_path]
code <<-EOH
tar xzf runit-2.1.1.tar.gz
cd runit-2.1.1
./build.sh
rpm_root_dir=`rpm --eval '%{_rpmdir}'`
rpm -ivh '/root/rpmbuild/RPMS/runit-2.1.1.rpm'
EOH
action :run
not_if rpm_installed
end
end
#### It fails because in 'build.sh' it runs "rpmdev-setuptree".
#### This creates rpmbuild directories in "$HOME/" but that doens't exist for the user/session running this script which _should_ be root.
#### So it creates them in "/" then the next line looks for "/root/.."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment