1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
#config.vm.box = "geerlingguy/centos7"
config.vm.provider :virtualbox do |vb|
vb.name = "pgauditlogtofile-centos7-test"
end
# Provision the VM
config.vm.provision "shell", inline: <<-SHELL
# Setup environment
echo 'export PG_VERSION=12' >> /etc/bashrc
echo 'export PATH=$PATH:/usr/pgsql-${PG_VERSION?}/bin' >> /etc/bashrc
source /etc/bashrc
# Install PostgreSQL
rpm -ivh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql${PG_VERSION}-server
# Install SCL llvm toolset 7 and enable it by default
yum install -y centos-release-scl-rh epel-release
yum install -y postgresql${PG_VERSION}-devel make openssl-devel llvm-toolset-7-clang llvm5.0
echo 'source scl_source enable devtoolset-7' >> /etc/bashrc
source /etc/bashrc
# Compile & install pgaudit
mkdir /pgaudit
curl -sSL https://github.com/pgaudit/pgaudit/archive/1.4.0.tar.gz | tar xzf - --strip-components=1 -C /pgaudit
make -C /pgaudit install USE_PGXS=1
# Compile & install pgauditlogtofile
make -C /pgauditlogtofile install USE_PGXS=1
# Create PostgreSQL cluster
/usr/bin/sudo -u postgres /usr/pgsql-${PG_VERSION}/bin/initdb -A trust -k /var/lib/pgsql/${PG_VERSION}/data
echo "shared_preload_libraries = 'pgaudit,pgauditlogtofile'" >> /var/lib/pgsql/${PG_VERSION}/data/postgresql.conf
/usr/bin/systemctl start postgresql-${PG_VERSION}
/usr/bin/sudo -u postgres psql -Xc 'create user vagrant superuser' postgres
# Configure pgaudit
/usr/bin/sudo -u postgres psql -Xc 'alter system set pgaudit.log = "all"' postgres
/usr/bin/sudo -u postgres psql -Xc 'alter system set pgaudit.log_parameter = on' postgres
/usr/bin/sudo -u postgres psql -Xc 'select pg_reload_conf()' postgres
# Enable pgauditlogtofile
/usr/bin/sudo -u postgres psql -Xc 'create extension pgauditlogtofile' postgres
/usr/bin/sudo -u postgres psql -Xc "select name, setting, unit from pg_settings where name like 'pgaudit%' order by name" postgres
SHELL
# Don't share the default vagrant folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# Mount project path for testing
config.vm.synced_folder "..", "/pgauditlogtofile", type: "virtualbox"
end
|