Chef how to run 2 variables, one or the other


#1

I have a chef recipe to install a software, but my environment some has java set to "/opt/jdk" and some to other "/usr/lib". I want to handle this within my installation recipe. Can someone help me with this case? To run one or the other, and if one is already ran, I do not want to the to run, it might fail the run. This is what i currently have below, but this will only work if the java is "/opt/jdk" and will fail on "/usr/lib"

    execute 'installing' do
    user  node['default']['user']
    group node['default]['group']
    cwd node['default']['home_dir']
    creates "#{node['default']['home_dir']}/#{node['default']['agent_dir']}"
    command <<-EOH
    echo -e N\\\\n#{node['default']['home_dir']}/#{node['default']['agent_dir']}\\\\nY | #{node['default'][ 
    'java_home']}/java -jar #{agent_jar}
    EOH

#2

A hacky way would be to add an only_if /opt/jdk exists and visa versa but you should try to standardise the path if possible, or if this is based on os/distro use that as you not if only if conditions


#3

yea.it would be best to standardize the path, we are currently going thru that, so i have to do something in the mean while


#4

Java installations are a nightmare because every single installer has its own distinct model of where things go.

Your situation may take as many as three distinct small recipes. One if Java is in the first place, one if it is in the second place, and one if it is someplace you haven't thought of. A typical Java programmer, and a careless Chef programmer, would only handle the two places they expect, but a sane devops person is willing to look past the "level of abstraction" and handle the exceptions.