Skip to content

Instantly share code, notes, and snippets.

@blissdev
Created August 25, 2013 08:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blissdev/6332593 to your computer and use it in GitHub Desktop.
Save blissdev/6332593 to your computer and use it in GitHub Desktop.
Installing Postgres 9.3rc1 and extensions with Ansible
TASK: [start postgres] ********************************************************
changed: [192.168.33.78] => {"changed": true, "cmd": "/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/logs/pgsql.log start && /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data reload ", "delta": "0:00:00.011510", "end": "2013-08-25 07:59:05.172814", "rc": 0, "start": "2013-08-25 07:59:05.161304", "stderr": "pg_ctl: another server might be running; trying to start server anyway", "stdout": "server starting\nserver signaled"}
TASK: [load pgcrypto] *********************************************************
failed: [192.168.33.78] => {"changed": true, "cmd": "/usr/local/pgsql/bin/psql -d template1 -c \"CREATE EXTENSION pgcrypto;\" ", "delta": "0:00:00.004287", "end": "2013-08-25 07:59:05.523699", "rc": 2, "start": "2013-08-25 07:59:05.519412"}
stderr: psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
FATAL: all hosts have already failed -- aborting
---
- hosts: vagrant
vars:
pgversion: 9.3rc1
pgpath: /usr/local/pgsql
#postgres: http://ftp.postgresql.org/pub/source/v9.3rc1/postgresql-9.3rc1.tar.gz
tasks:
- name: update apt
apt: update_cache=yes
sudo: yes
- name: install dependencies
apt: pkg=$item state=installed
sudo: yes
with_items:
- build-essential
- subversion
- git
- vim
- libreadline-dev
- zlib1g-dev
- flex
- bison
- libxml2-dev
- libxslt1-dev
- libssl-dev
- name: download postgres
get_url: dest=/home/vagrant/postgresql-{{pgversion}}.tar.gz
url=http://ftp.postgresql.org/pub/source/v{{pgversion}}/postgresql-{{pgversion}}.tar.gz
- name: decompress postgres source
command: tar xzf postgresql-{{pgversion}}.tar.gz
- name: install postgres
shell: cd postgresql-{{pgversion}} && ./configure && make && sudo make install && touch .ansible-make.lock
creates=/home/vagrant/postgresql-{{pgversion}}/.ansible-make.lock
- name: create postgres user
user: name=postgres state=present
sudo: yes
# for some reason can't do them in the same task
- name: create postgres log directory
sudo: yes
file: state=directory path=/usr/local/pgsql/logs group=postgres owner=postgres
- name: create postgres data directory
sudo: yes
file: state=directory path=/usr/local/pgsql/data group=postgres owner=postgres
- name: update postgres user path with postgres
shell: echo PATH=/usr/local/bin:$PATH >> ~/.bashrc
sudo: yes
sudo_user: postgres
- name: update default user with postgres
shell: echo PATH=/usr/local/pgsql/bin:$PATH >> ~/.bashrc
- name: initdb
command: /usr/local/pgsql/bin/initdb --locale=en_US.UTF-8 --encoding=UNICODE -D {{pgpath}}/data
creates={{pgpath}}/data/PG_VERSION
sudo: yes
sudo_user: postgres
- name: update postgres connection configuration
copy: src=files/pg_hba.conf dest=/usr/local/pgsql/data/pg_hba.conf
backup=yes
mode=640
owner=postgres
group=postgres
copy: src=files/postgresql.conf dest=/usr/local/pgsql/data/postgresql.conf
backup=yes
mode=644
owner=postgres
group=postgres
sudo: yes
sudo_user: postgres
notify:
- start postgres
# / of postgres install
- name: get v8
subversion: repo=http://v8.googlecode.com/svn/branches/3.16/ dest=/home/vagrant/v8
- name: install v8
shell: make dependencies && make native library=shared
chdir=/home/vagrant/v8
creates=/home/vagrant/v8/out/native/lib.target/libv8.so
- name: copy so
shell: cp /home/vagrant/v8/out/native/lib.target/libv8.so /usr/lib
creates=/usr/lib/libv8.so
sudo: yes
- name: get plv8js
git: repo=https://code.google.com/p/plv8js/ dest=/home/vagrant/plv8js
- name: install plv8js
shell: make V8_SRCDIR=../v8/ PG_CONFIG={{pgpath}}/bin/pg_config && sudo make install PG_CONFIG={{pgpath}}/bin/pg_config
chdir=/home/vagrant/plv8js
creates={{pgpath}}/lib/plv8.so
#- name: instantiate plv8
# shell: "{{pgpath}}/bin/psql -d template1 -c \"CREATE EXTENSION plv8;\""
# sudo: yes
# sudo_user: postgres
# / of plv8 install
- name: install pgcrypto
shell: make && sudo make install
chdir=/home/vagrant/postgresql-{{pgversion}}/contrib/pgcrypto
creates={{pgpath}}/lib/pgcrypto.so
#- name: instantiate pgcrypto
# shell: "{{pgpath}}/bin/psql -d template1 -c \"CREATE EXTENSION pgcrypto;\""
# sudo: yes
# sudo_user: postgres
# / of pgcrypto install
#
- name: start postgres
shell: "{{pgpath}}/bin/pg_ctl -D {{pgpath}}/data -l {{pgpath}}/logs/pgsql.log start"
sudo: yes
sudo_user: postgres
- name: load pgcrypto
shell: "{{pgpath}}/bin/psql -d template1 -c \"CREATE EXTENSION pgcrypto;\""
sudo: yes
sudo_user: postgres
- name: load plv8
shell: "{{pgpath}}/bin/psql -d template1 -c \"CREATE EXTENSION plv8;\""
sudo: yes
sudo_user: postgres
@gmustdie
Copy link

I'm guessing that the server didn't get the "postgresql contrib" package installed.
https://packages.debian.org/search?searchon=contents&keywords=pgcrypto.control&mode=path&suite=stable&arch=any

@blissdev
Copy link
Author

Nice with the 9 year later response! I have no recollection if it was figured out or not.

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