engineyard / ey-cookbooks-stable-v7

Other
6 stars 5 forks source link

Chef fails when installing PostgreSQL extensions #221

Open dvalfre opened 9 months ago

dvalfre commented 9 months ago

Steps to reproduce: 1) Create file /db/postgreql/entensions.json with the following structure:

{
  "<dbname>": ["hstore"]
}

2) Run Chef on the instance.

Desired output:

Current behavior:

================================================================================
Error executing action `run` on resource 'ruby_block[process extensions.json]'
================================================================================

NameError
---------
uninitialized constant Chef::Resource::PostgresqlPgExtension

Cookbook Trace: (most recent call first)
----------------------------------------
/etc/chef/recipes/cookbooks/ey-postgresql/recipes/server_configure.rb:280:in `block (3 levels) in from_file'
/etc/chef/recipes/cookbooks/ey-postgresql/recipes/server_configure.rb:279:in `each'
/etc/chef/recipes/cookbooks/ey-postgresql/recipes/server_configure.rb:279:in `block (2 levels) in from_file'

Resource Declaration:
---------------------
# In /etc/chef/recipes/cookbooks/ey-postgresql/recipes/server_configure.rb

275: ruby_block "process extensions.json" do
276: block do
277: # run_context = Chef::RunContext.new(node, {})
278: exts = JSON.parse(::File.read(node["pg_extensions_file"]))
279: exts.each do |db_name, exts|
280: run_context.resource_collection << r = Chef::Resource::PostgresqlPgExtension.new("install #{exts.join(',')} in database #{db_name}", run_context)
281: r.db_name = db_name
282: r.ext_name = exts
283: end
284: end
285: only_if { ::File.exist?(node["pg_extensions_file"]) }
286: end
287:
dvalfre commented 9 months ago

Workaround: add the extensions by: 1) Connecting to the db engine; 2) Installing the desired extension(s) by running CREATE EXTENSION <extension_name>; 3) Checking the status by running \dx.