0

I'm wanting a really basic install of postgres, and the postgres-formula/postgres is just too crazy. I just want to install postgres version 9.5.1 on a single minion.

Here's something I've tried, that I know doesn't work.

/srv/salt/top.sls

base:
  '*':
    - postgresql

/srv/salt/postgresql/init.sls

postgresql:
  pkg.installed:
      - version: 9.5.1

According to the documentation here, this is the correct format. I thought maybe I should have the 9.5.3 in a different format, but I can't find where to figure that out.


Update 1

I'm using ubuntu 14.04 on the minion, and the master.

The output of apt-cache policy postgresql is

postgresql:
  Installed: (none)
  Candidate: 9.3+154ubuntu1
  Version table:
     9.3+154ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
     9.3+154 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
2
  • What OS do you use ? if centos print out the result of the following command: yum --showduplicates list postgresql | expand and if ubuntu: apt-cache policy postgresql because you need first to make sure that there is a version with the same number available on your system so salt can install it Commented Jun 23, 2016 at 19:13
  • Thanks, I'll update with that output. Since it's only outputting 9.3, how would I get salt to install 9.5? Commented Jun 23, 2016 at 19:30

4 Answers 4

1

In order to install Postgresql 9.5 using saltstack.

First make sure to to do as this article says in your ubuntu minion in order to make postgresql 9.5 available to your system to install. or even you can write a state that automates the whole steps. adding the repository and installing postgresql 9.5

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for being correct on the logic, and helping. Thanks for showing me how to find out which versions are available through apt-cache. However, the way to do this through salt is listed in the answer I found on the saltstack irc.
1

The answer offered by @trueCamelType does not appear to work with a CentOS 7 based minion. The following does work:

init.sls

install-postgresql96-repository:
  cmd.run:
    - name: rpm -U --force https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

install-postgresql96-server:
  cmd.run:
    - name: yum --disablerepo=postgresql -y install postgresql96-server

postgresql-first-run-init:
  cmd.run:
    - name: /usr/pgsql-9.6/bin/postgresql96-setup initdb
    - unless: stat /var/lib/pgsql/9.6/data/postgresql.conf
    - runas: root

start-postgresql96-server:
  cmd.run:
    - name: systemctl start postgresql-9.6

enable-postgresql96-autostart:
  cmd.run:
    - name: systemctl enable postgresql-9.6

The rpm command is run with --force so that it can be repeated without issuing an 'error' indicating the package has already been installed. Makes the salt output prettier.

The yum command is run with --disablerepo=postgresql to prevent salt from trying to use an external repo.

It is procedural and not elegant but I found that futzing with pkgrepo.managed was more trouble than it was worth. That said would love to see a solution to installing postgresql on Centos 7 using 'pkgrepo.managed`.

Comments

1

If you want a really basic install of Postgres, just do the following to install 9.5 from https://www.postgresql.org/. Something like this works out-of-the-box.

$ sudo -s
$ cd /srv/salt/
$ git clone https://github.com/saltstack-formulas/postgres-formula.git postgres
$ ln -s /srv/salt/postgres/postgres /srv/salt/postgres
$ vi /srv/salt/top.sls && cat /srv/salt/top.sls 
#format: YAML

base:
  '*':
    - postgres

$ salt-call state.highstate --local

If you want to different behavior set pillar (i.e. in /srv/pillar/postgres.sls) accordingly first.

postgres:
  use_upstream_repo: True
  version: '9.6'

Comments

0

This should be done through salt using pkgrepo.managed. The solution is below.

init.sls

 postgresql:
  pkgrepo.managed:
    - name: deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
    - dist: trusty-pgdg
    - file: /etc/apt/sources.list.d/psql.list
    - key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
    - require_in:
      - pkg: postgresql
  pkg.installed:
    - name: postgresql-9.5
    - refresh: True
  service:
    - running

I got this answer through a combination of the saltstack irc, and the salt docs.

1 Comment

Problematic with CentOS 7 (and probably earlier versions). See my answer for your initial question when the minion is running on CentOS 7. I realize you updated the question to refer to ubuntu, but this seemed an appropriate place to answer the original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.