3

I am having a problem. I am trying to get a node IP that's running postgresql and is the replication master. So I can implant the IP to repmgr cookbook so it will automatically set it in to SSH config file. I need it because I am not running SSH on port 22 so I need to automatize the process.

This is the configure.rb file:

template File.join(node[:repmgr][:pg_home], '.ssh/config') do
  source 'ssh_config.erb'
  mode 0644
  owner node[:repmgr][:system_user]
  group node[:repmgr][:system_user]
  variables( :hosts => Array(master_node[:ipaddress]) )
end

directory File.dirname(node[:repmgr][:config_file_path])

template node[:repmgr][:config_file_path] do
  source 'repmgr.conf.erb'
  mode 0644
end

Master node IP address is taken from attributes (default.rb):

default[:repmgr][:addressing][:master] = nil

I need to change the nil to something else so I can get the IP of the master server so slave aka. standby server can add it's IP to SSH config so it will replicate over my SSH port not the default 22 port.

I hope someone can help be because I am a really new to Ruby and I only know the basics of it.

Thank you. I hope you understand my question.

cr0c
  • 173
  • 2
  • 10

1 Answers1

3

If you are using chef-server, then you can find other provisioned nodes through search in recipe. You can search for nodes by different properties: such as role, recipe, environment, name and so on. I hope your replication master node has some attribute that makes it unique, for example postgres recipe or replication-master role in run_list.

nodes = search( :node, 'recipes:postgres' )

or

nodes = search( :node, 'role:replication-master' )

Search returns an array of nodes that have the corresponding attributes. And then:

node.default[:repmgr][:addressing][:master] = nodes.first[:ipaddress]

The code should be written in recipe file, not in attributes.

Draco Ater
  • 20,820
  • 8
  • 62
  • 86
  • To tack on, if you consistently use the same master server by name, this would suffice: nodes = search(:node, "name:repmaster.example.com") - the node.default[:repmgr][:addressing][:master] = nodes.first[:ipaddress] still holds true. – Stephan Mar 21 '14 at 02:26