Permalink
Browse files

support explicit `postgresql.conf` templating

  • Loading branch information...
1 parent fd3fce6 commit 394bbc1a2e4f3fd851c9abf8e405320b6ad299e9 @phlipper committed Feb 3, 2013
View
94 README.md
@@ -40,9 +40,11 @@ The following platforms are supported by this cookbook, meaning that the recipes
This cookbook installs the postgresql components if not present, and pulls updates if they are installed on the system.
-Additionally this cookbook provides three definitions to create, alter and delete users as well as create and drop databases or setup extensions. Usage is as follows:
+This cookbook provides three definitions to create, alter, and delete users as well as create and drop databases, or setup extensions. Usage is as follows:
+### Users
+
```ruby
# create a user
pg_user "myuser" do
@@ -60,7 +62,27 @@ end
pg_user "myuser" do
action :drop
end
+```
+Or add users via attributes:
+
+```json
+"postgresql": {
+ "users": [
+ {
+ "username": "dickeyxxx",
+ "password": "password",
+ "superuser": true,
+ "createdb": true,
+ "login": true
+ }
+ ]
+}
+```
+
+### Databases and Extensions
+
+```ruby
# create a database
pg_database "mydb" do
owner "myuser"
@@ -88,46 +110,57 @@ pg_database "mydb" do
end
```
-Or add the user/database via attributes:
+Or add the database via attributes:
-```ruby
-:users => [
- {
- :username => "dickeyxxx",
- :password => "password",
- :superuser => true,
- :createdb => true,
- :login => true
- }
-],
-
-:databases => [
- {
- :name => "my_db",
- :owner => "dickeyxxx",
- :template => "template0",
- :encoding => "utf8",
- :locale => "en_US.UTF8",
- :extensions => "hstore"
+```json
+"postgresql": {
+ "databases": [
+ {
+ "name": "my_db",
+ "owner": "dickeyxxx",
+ "template": "template0",
+ "encoding": "utf8",
+ "locale": "en_US.UTF8",
+ "extensions": "hstore"
+ }
+ ]
+}
+```
+
+### Configuration
+
+The `postgresql.conf` configuration may be set one of two ways:
+
+* set individual node attributes to be interpolated into the default template
+* create a custom configuration hash to write a custom file
+
+To create a custom configuration, set the `node["postgresql"]["conf"]` hash with your custom settings:
+
+```json
+"postgresql": {
+ "conf": {
+ "data_directory": "/dev/null",
+ // ... all options explicitly set here
}
-]
+}
```
-Or add contents to the pg_hba.conf via attributes:
+You may also set the contents of `pg_hba.conf` via attributes:
-```ruby
+```json
"postgresql": {
"pg_hba": [
- { type: "local", db: "all", user: "postgres", addr: "", method: "ident" },
- { type: "local", db: "all", user: "all", addr: "", method: "trust" },
- { type: "host", db: "all", user: "all", addr: "127.0.0.1/32", method: "trust" },
- { type: "host", db: "all", user: "all", addr: "::1/128", method: "trust" },
- { type: "host", db: "all", user: "postgres", addr: "127.0.0.1/32", method: "trust" },
- { type: "host", db: "all", user: "username", addr: "127.0.0.1/32", method: "trust" }
+ { "type": "local", "db": "all", "user": "postgres", "addr": "", "method": "ident" },
+ { "type": "local", "db": "all", "user": "all", "addr": "", "method": "trust" },
+ { "type": "host", "db": "all", "user": "all", "addr": "127.0.0.1/32", "method": "trust" },
+ { "type": "host", "db": "all", "user": "all", "addr": "::1/128", "method": "trust" },
+ { "type": "host", "db": "all", "user": "postgres", "addr": "127.0.0.1/32", "method": "trust" },
+ { "type": "host", "db": "all", "user": "username", "addr": "127.0.0.1/32", "method": "trust" }
]
}
```
+
## Attributes
```ruby
@@ -495,7 +528,6 @@ default["postgresql"]["custom_variable_classes"] = ""
## TODO
* Add support for replication setup
-* Add support for custom config files
* Add installation and configuration for the following packages:
```
View
6 recipes/server.rb
@@ -68,11 +68,13 @@
end
# postgresql
+pg_template_source = node["postgresql"]["conf"].any? ? "custom" : "standard"
template "/etc/postgresql/#{pg_version}/main/postgresql.conf" do
- source "postgresql.conf.erb"
+ source "postgresql.conf.#{pg_template_source}.erb"
owner "postgres"
group "postgres"
mode "0644"
+ variables(:configuration => node["postgresql"]["conf"])
notifies :restart, "service[postgresql]"
end
@@ -85,13 +87,15 @@
notifies :restart, "service[postgresql]", :immediately
end
+# setup users
node["postgresql"]["users"].each do |user|
pg_user user["username"] do
privileges :superuser => user["superuser"], :createdb => user["createdb"], :login => user["login"]
password user["password"]
end
end
+# setup databases
node["postgresql"]["databases"].each do |database|
pg_database database["name"] do
owner database["owner"]
View
10 templates/default/postgresql.conf.custom.erb
@@ -0,0 +1,10 @@
+# generated by Chef for node <%= node["fqdn"] %>
+#
+# -----------------------------
+# PostgreSQL configuration file
+# -----------------------------
+#
+
+<% @configuration.each_pair do |key, value| %>
+<%= "#{key} = '#{value}'" %>
+<% end %>
View
0 templates/default/postgresql.conf.erb → ...ates/default/postgresql.conf.standard.erb
File renamed without changes.

0 comments on commit 394bbc1

Please sign in to comment.