Kanrisuru

Manage a Cluster of Hosts

Kanrisuru can manage multiple hosts at the same time with the Kanrisuru::Remote::Cluster.

Instantiation

To instantiate a cluster, add 1 or more hosts:

require 'kanrisuru'

cluster = Kanrisuru::Remote::Cluster.new({
  host: 'remote-host-1',
  username: 'ubuntu',
  keys: ['~/.ssh/remote_1_id_rsa']
}, {
  host: 'remote-host-2',
  username: 'centos',
  keys: ['~/.ssh/remote_2_id_rsa']
}, {
  host: 'remote-host-3',
  username: 'opensuse',
  keys: ['~/.ssh/remote_3_id_rsa']
})


You can also add a host to a cluster that’s already been created

host = Kanrisuru::Remote::Host.new(host: 'remote-host-4', username: 'rhel', keys: ['~/.ssh/remote_4_id_rsa'])

cluster << host 

Run commands

Kanrisuru at this point only runs commands sequentially. We plan on creating a parallel run mode in a future release.

To run across all hosts with a single command, cluster will return a array of result hashes

cluster.whoami
[
  {
    :host => "remote-host-1",
    :result => #<Kanrisuru::Result:0x880 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="ubuntu"> @command=sudo -u ubuntu /bin/bash -c "whoami">
  },
  {
    :host => "remote-host-2",
    :result => #<Kanrisuru::Result:0x940 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="centos"> @command=sudo -u centos /bin/bash -c "whoami">
  }
]


You can also access each host individually to run a command conditionaly within an iterable block

cluster.each do |host|
  case host.os.release
  when 'ubuntu', 'debian'
    host.apt('update')
  when 'centos', 'redhat', 'fedora'
    host.yum('update')
  when 'opensuse_leap', 'sles'
    host.zypper('update')
  end
end