我想运行以下安装脚本来配置通过虚拟机部署的postgresql数据库,使用puppet通过vagrant配置:
#!/bin/bash -e
sudo su - postgres
createdb testdb
psql -s tm351test -c "create user test password 'test';GRANT ALL PRIVILEGES ON DATABASE testdb TO test;"
touch /root/postgresql.done
我的流浪汉配置采用以下形式:
package {
[
'postgresql',
'postgresql-client'
]: ensure => latest;
}
file {
'/root/postgresql.setup':
source => 'puppet:///modules/infinite_interns/root/postgresql.setup',
owner => root,
group => root,
mode => '0744';
}
#TO DO - how do we guarantee the postgresql server is running and tools available?
exec {
'setup-postgresql':
cwd => '/root',
command => '/root/postgresql.setup',
creates => '/root/postgresql.done';
}
service {
'postgresql':
ensure => running,
enable => true;
}
Package['postgresql'] -> Service['postgresql']
在运行配置脚本之前,如何保证安装并运行postgresql服务器以及可用的命令行工具?
我是Puppet的新手 - 如果创建的文件postgresql.done
存在,Exec()是否无法运行?
我怀疑psql
命令也可能期望确认"返回"执行命令 - 我该怎么做?
答案 0 :(得分:0)
您最好的选择是使用postgres模块https://forge.puppetlabs.com/puppetlabs/postgresql
答案 1 :(得分:0)
可以轻松安装官方postgresql module:
puppet module install puppetlabs-postgresql
或在Puppetfile
添加以下内容:
mod 'puppetlabs-postgresql'
配置可能如下所示:
class { 'postgresql::globals':
encoding => 'UTF-8',
locale => 'en_US.UTF-8',
version => '9.6',
}->
class { 'postgresql::server':
ip_mask_deny_postgres_user => '0.0.0.0/32',
ip_mask_allow_all_users => '0.0.0.0/0',
listen_addresses => '*',
version => '9.6',
}
postgresql::server::db { 'testdb':
user => 'test',
password => postgresql_password('test', 'testpassword'),
}
postgresql::server::pg_hba_rule { 'allow connection from ...':
description => "Open up PostgreSQL for access from test domain",
type => 'host',
database => 'testdb',
user => 'test',
address => '.testdomain.com',
auth_method => 'md5',
}