We currently use puppet 3.8.7 to provision a large number of AWS EC2 instances.
Since these machines have small and slow root volumes, we symlink certain directories from e.g. /var to /mnt.
This leads to manifests riddles with segments like this:
group { 'postgres':
ensure => present,
system => true,
}
user { 'postgres':
ensure => present,
comment => 'PostgreSQL administrator',
gid => 'postgres',
home => '/var/lib/postgresql',
require => Group['postgres'],
}
file { '/mnt/postgresql':
ensure => directory,
owner => 'postgres',
group => 'postgres',
mode => '0755',
require => User['postgres'],
}
file { '/var/lib/postgresql':
ensure => link,
target => '/mnt/postgresql',
require => File['/mnt/postgresql'],
before => Class['dbserver'],
}
This is
ugly
overly verbose
and
error prone if an implicit dependency (e.g. on postgresql-client) creates the directory before the
file
statement is evaluated.
So I'm wondering, how do other people tackle this?
Is there a better way to ensure that
- such symlinks always get created before the package containing the directory gets installed
but
- they only get created if a package containing the directory is going to be installed?
The puppet files are reflecting your system configuration, and are thus a bit ugly. I suggest one of the following solutions:
Restructuring your system configuration might help a bit. Do not mount your device to /mnt/postgres, but to /var/lib/postgresql, or maybe use a
/var
partition.If your only problem is postgres being installed before your symlink creation, this is easy: Enforce creation of the symlink before the postgres installation.
If you want to fix systems where your problem already persists, I recommend implementing a fixing
exec
statement, similar to this:The script could possibly shutdown the postgres, sync the data to
/mnt/postgres
, delete/var/lib/postgres
.If you simply want to force director deletion for the file resource, you can use the
force
option, as described in the Puppet documentationChange the data directories of your applications. Most applications allow this. For Postgres, the settign
data_directory()
should help you, also see the PostgreSQL Documentation.