package "postgres" do
version "9.3"
action :install
provider Chef::Provider::Package::Apt
end
template "/etc/postgresql/9.3/main/pg_hba.conf" do
source "pg_hba.conf.erb"
mode 0660
user "postgres"
group "postgres"
end
execute "createdb ucmsdb" do
user "postgres"
not_if "psql --list | grep -v grep | grep ucmsdb", :user => "postgres"
end
You could wrap the same logic you’re trying to do in an LWRP:
use_inline_resources
action :install do
package "postgres" do
version "9.3"
action :install
provider Chef::Provider::Apt
end
template "/etc/postgresql/9.3/main/pg_hba.conf" do
source "pg_hba.conf.erb"
mode 0660
user "postgres"
group "postgres"
end
execute "createdb ucmsdb" do
user "postgres"
not_if "psql --list | grep -v grep | grep ucmsdb", :user => "postgres"
end
end
Then leverage that in your recipe (you’ll have to write the resource too, which I’m going to leave to you):
custom_postgres “installer” do
action :install
end
All 3 of the resources are already idempotent, so your node attribute isn’t needed. But if your real installer is more complicated you can add conditional checks inside the lightweight provider. They will not be executed until your resource is.
package "postgres" do
version "9.3"
action :install
provider Chef::Provider::Package::Apt
end
template "/etc/postgresql/9.3/main/pg_hba.conf" do
source "pg_hba.conf.erb"
mode 0660
user "postgres"
group "postgres"
end
execute "createdb ucmsdb" do
user "postgres"
not_if "psql --list | grep -v grep | grep ucmsdb", :user => "postgres"
end