厨师独奏不更新postgres pg_hba.conf
问题描述:
我正在使用Chef Solo配置Vagrant虚拟机。下面是相关Vagrantfile片段:厨师独奏不更新postgres pg_hba.conf
chef.run_list = [
"databox::default",
"mydbstuff"
]
chef.json = {
"postgresql": {
"config" : {
"listen_addresses": "*"
},
"pg_hba": [
{"type": "local", "db": "all", "user": "postgres", "addr": null, "method": "ident"},
{"type": "local", "db": "all", "user": "all", "addr": null, "method": "md5"},
{"type": "host", "db": "all", "user": "all", "addr": "127.0.0.1/32", "method": "md5"},
{"type": "host", "db": "all", "user": "all", "addr": "::1/128", "method": "md5"},
{"type": "local", "db": "all", "user": "vagrant", "addr": null, "method": "ident"},
{"type": "host", "db": "all", "user": "all", "addr": "192.168.248.1/24", "method": "md5"}
]
},
"databox": {
"db_root_password": "abc123",
"databases": {
"postgresql": [
{ "username": "db1", "password": "abc123", "database_name": "db1" },
{ "username": "db2", "password": "abc123", "database_name": "db2" }
]
}
}
}
的mydbstuff::default
配方如下:
postgresql_connection_info = {
:host => "localhost",
:port => node['postgresql']['config']['port'],
:username => 'postgres',
:password => node['postgresql']['password']['postgres']
}
postgresql_database_user 'vagrant' do
connection postgresql_connection_info
password 'vagrant'
action :create
end
node['databox']['databases']['postgresql'].each do |db|
postgresql_database_user 'vagrant' do
connection postgresql_connection_info
action :grant
database_name db.database_name
end
end
我试图让当地vagrant
用户连接,无需输入密码,并通过VirtualBox的任何用户私人网络。我的chef.json
中的pg_hba
数组有四条线从默认配置复制,两条线用于执行我想要执行的其他操作。 如果我手动添加这两行到pg_hba.conf
文件,他们工作得很好。
问题是我的更改实际上没有写入pg_hba.conf
文件。什么阻止他们被写入?
答
看起来数据库食谱overwrites the Postgres permissions array使用node.set
而不是仅仅修改它需要的部分。
我已向项目提交了a pull request以更改此行为,以便可以将其他条目添加到该文件中。
答
我面对厨师独奏的问题。我的出路是为pg_hba.conf创建一个模板,并在配方执行结束时进行替换。