Skip to content

Instantly share code, notes, and snippets.

@rija
Last active January 9, 2018 11:01
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 rija/163844286576609087f5bd4bad0c4923 to your computer and use it in GitHub Desktop.
Save rija/163844286576609087f5bd4bad0c4923 to your computer and use it in GitHub Desktop.
two (three) ways of fixing the existing postgresql package problem in Chef

The conflict

both code try to fix the same problem

# To do: exclude Centos 6 postgres packages
bash 'Add postgres package repositories' do
		user 'root'
		cwd '/tmp'
    code <<-EOH
<<<<<<< HEAD
        CHECK_RPM=$(rpm -qa | grep pgdg-centos91)
        if [ "$CHECK_RPM" != "" ]
        then
            echo "pgdg-centos91*.rpm is installed!"
        else
            curl -O https://download.postgresql.org/pub/repos/yum/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm
            rpm -ivh pgdg*
        fi
=======
        curl -O https://download.postgresql.org/pub/repos/yum/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm
        rpm -q pgdg-centos91-9.1-6.noarch || rpm -ivh pgdg*
>>>>>>> Affiliate Login (#64): problem with vagrant provisioning of gigadb-website
    EOH
end

the third option

the advantage of the HEAD code is that it doesn't even download the rpm if it is already installed.

Which made me think of a way to improve the feature branch code into:

rpm -q pgdg-centos91-9.1-6.noarch \
    || curl -O https://download.postgresql.org/pub/repos/yum/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-6.noarch.rpm \
    && rpm -ivh pgdg* 

but the HEAD code is still better as it is not querying a specific dot dot version of the rpm so it's more flexible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment