Search code examples
chef-infrachef-recipecookbook

include_recipe makes everything before to be skipped


I want to use postgresql community cookbook, but I want packages from a different repo. That's why I add it with yum_repository resource in my wrapper cookbook. Here is my wrapper cookbook recipe:

yum_repository 'PostgresBDR' do
  description 'Postgres BDR repo'
  baseurl 'http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/yum/redhat-$releasever-$basearch'
  gpgkey 'http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/RPM-GPG-KEY-2NDQ-BDR-94'
  action :create
end

node.default['postgresql']['version'] = '9.4'
node.default['postgresql']['server']['service_name'] = 'postgresql-9.4'
node.default['postgresql']['server']['packages'] = %w(postgresql-bdr94-server postgresql-bdr94-bdr)
node.default['postgresql']['client']['packages'] = %w(postgresql-bdr94 postgresql-bdr94-devel)
node.default['postgresql']['setup_script'] = 'postgresql94-setup'

include_recipe 'postgresql::ruby'
include_recipe 'postgresql::server'

The problem is that BDR repo does not get added until I comment two latest strings with include_recipe. So I can accomplish installation in two parts.

  1. Comment two latest lines with include_recipe and apply cookbook
  2. Uncomment and apply cookbook again

Why it does not work as I expect? Tried to move yum_repository into a separate recipe and include_recipe it too but nothing changed.


Solution

  • The postgresql::ruby recipe does the install at compile time instead of the usual converge time because of its intended use. You'll have to set up the repo at compile time too.

    yum_repository 'PostgresBDR' do
      description 'Postgres BDR repo'
      baseurl 'http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/yum/redhat-$releasever-$basearch'
      gpgkey 'http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/RPM-GPG-KEY-2NDQ-BDR-94'
      action :nothing
    end.run_action(:create)
    

    You can find more detailed info on the two phases at https://coderanger.net/two-pass/.