Search code examples
pythonrubychef-infrachef-recipeaws-opsworks

Opsworks log shows a bash block ran successfully but it did not


I've this block in one of the recipes which is being included in other recipe.

bash 'setup' do
    cwd "#{node[:'python-virtualenv'][:home]}"
    user 'ubuntu'
    environment "HOME" => "#{node[:'python-virtualenv'][:home]}"
    code <<-EOH
    sudo add-apt-repository -y ppa:fkrull/deadsnakes
    sudo apt-get update
    sudo apt-get -yq install python3.5
    curl -s https://bootstrap.pypa.io/get-pip.py | sudo python3.5
    sudo pip3.5 install virtualenv virtualenvwrapper
    echo "export WORKON_HOME=#{node[:'python-virtualenv'][:home]}.virtualenvs/" > #{node[:'python-virtualenv'][:home]}.bash_profile
    echo "export VIRTUALENVWRAPPER_PYTHON=$(which python3.5)" > #{node[:'python-virtualenv'][:home]}.bash_profile
    echo "source /usr/local/bin/virtualenvwrapper.sh" >> #{node[:'python-virtualenv'][:home]}.bash_profile
    EOH
end

The logs say that this block got executed but when I ssh into the instance, it did not get installed.

Here's the relevant part of the log

[2018-03-07T09:59:33+00:00] INFO: Processing bash[setup] action run (app::default line 12)
[2018-03-07T09:59:40+00:00] INFO: bash[setup] ran successfully

Solution

  • Add set -e to the top of your shell script and you would probably see it fail on one of the intermediary commands. Why are you running as a non-root user and then trying to use sudo though? Overall this seems like a very odd shell script. Might want to add set -x to help with debugging too.