Created: 2018-02-07 — modified: 2018-07-30 — tags: CFEngine
TL;DR: copy libs to
/var/cfengine/lib/postgresql/ and extensions - to
This is the environment I was working with:
OS: CentOS 6.9
CFEngine: 3.7.3 Enterprise
PostgreSQL version: 9.3 (shipped together with CFEngine)
Desired plugin: pg-dns-resolve so you could issue
Download the script above and inside it you will find installation instructions:
* Make sure, you have ip4r installed. Get it from: http://pgfoundry.org/projects/ip4r/ * Make sure, you have PL/Pythonu installed and are allowed to add new functions * PL/Pythonu must be built against Python >= 2.4 * psql [YOUR OPTIONS] < plpython_dns-functions.sql
You actually don't need to build ip4r and PL/Python from sources, since PostgreSQL provides packages for them (but not for pg-dns-resolve). You can download them from here: https://ftp.postgresql.org/pub/repos/yum/9.3/redhat/rhel-6.9-x86_64 (Note that URL mentions PostgreSQL 9.3 and RedHat 6.9 versions, what corresponds to our environment)
Navigate to above URL and search (Ctrl+F) for "ip4r". You will find two packages:
ip4r93-2.2-1.rhel6.x86_64.rpm - note that they differ only in version, so let's install latest one :-)
SSH into your your CFEngine Hub machine and issue the following commands:
Download the ip4r package
Install it ignoring dependencies. RPM will complain that ip4r requires PostgreSQL to be installed and is broken without it, but that's fine - we don't need a system PostgreSQL, we have one shipped with CFEngine, instead. Actually, we need only some files from this RPM package:
rpm -U ip4r93-2.2-1.rhel6.x86_64.rpm --nodeps
List extracted files:
rpm -q --filesbypkg ip4r93
We see that this package installed
ip4r.sointo library path
/usr/pgsql-9.3/lib/and few extensions to
Copy them to CFEngine-PostgreSQL dirs:
cp /usr/pgsql-9.3/lib/ip4r.so /var/cfengine/lib/postgresql/ cp /usr/pgsql-9.3/share/extension/ip4r* /var/cfengine/share/postgresql/extension
Let CFEngine's PostgreSQL know about new extension (you need to
cfpostgres-user-readable dir before running
cd /tmp su cfpostgres -c "/var/cfengine/bin/psql cfmp -c 'CREATE EXTENSION ip4r;'"
This part is done!
Same as for ip4r: find latest package in the package list (at the moment of writing this guide it was
postgresql93-plpython-9.3.20-5PGDG.rhel6.x86_64.rpm) and run the following commands on your hub:
rpm -U postgresql93-plpython-9.3.20-5PGDG.rhel6.x86_64.rpm --nodeps
rpm -q --filesbypkg postgresql93-plpython
cp /usr/pgsql-9.3/lib/plpython2.so /var/cfengine/lib/postgresql/ cp /usr/pgsql-9.3/share/extension/plpython* /var/cfengine/share/postgresql/extension
Install (note that here command is slightly different, since we're installing language, not extension):
cd /tmp su cfpostgres -c "/var/cfengine/bin/psql cfmp -c 'CREATE LANGUAGE plpythonu;'"
Here everything is easier - just download and follow the official 1-command "guide":
cd /tmp su cfpostgres -c "/var/cfengine/bin/psql cfmp -f plpython_dns-functions.sql"
su cfpostgres -c "/var/cfengine/bin/psql cfmp -c \"select hostbyname('www.google.ru')\""
hostbyname ---------------- 126.96.36.199 (1 row)