diff --git a/CHANGELOG.md b/CHANGELOG.md index d7d3506..a656da0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### ##### Features - +* A new subclass to automates the creation of a cluster from the master and join from other nodes. ##### Changes * Update README.md. diff --git a/manifests/hypervisor.pp b/manifests/hypervisor.pp index aca08b8..7580b51 100644 --- a/manifests/hypervisor.pp +++ b/manifests/hypervisor.pp @@ -63,16 +63,20 @@ class proxmox::hypervisor ( $vz_service_manage = $proxmox::params::vz_service_manage, $vz_service_enabled = $proxmox::params::vz_service_enabled, $labs_firewall_rule = $proxmox::params::labs_firewall_rule, + $cluster_master_ip = undef, + $cluster_name = undef, ) inherits proxmox::params { include '::proxmox::hypervisor::preconfig' include '::proxmox::hypervisor::install' include '::proxmox::hypervisor::config' include '::proxmox::hypervisor::service' + include '::proxmox::hypervisor::cluster' Class['proxmox::hypervisor::preconfig'] -> Class['proxmox::hypervisor::install'] -> Class['proxmox::hypervisor::config'] -> - Class['proxmox::hypervisor::service'] + Class['proxmox::hypervisor::service'] -> + Class['proxmox::hypervisor::cluster'] } # Public class: proxmox::hypervisor diff --git a/manifests/hypervisor/cluster.pp b/manifests/hypervisor/cluster.pp new file mode 100644 index 0000000..f12e282 --- /dev/null +++ b/manifests/hypervisor/cluster.pp @@ -0,0 +1,52 @@ +# == Class: proxmox::hypervisor::cluster +# +# Manage the Proxmox cluster. +# +class proxmox::hypervisor::cluster +{ + + File { + owner => root, + group => root, + mode => 644, + } + + Exec { + path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ], + logoutput => 'on_failure', + } + + if $::is_proxmox == 'true' and $proxmox::hypervisor::cluster_master_ip != undef and $proxmox::hypervisor::cluster_name != undef { + # Ensure the root user got an ssh-key + exec { 'create ssh-key for root': + command => 'ssh-keygen -t rsa -f /root/.ssh/id_rsa -b 2048 -N "" -q', + creates => '/root/.ssh/id_rsa.pub', + } + + # Test if this node should be the master or a node + if has_interface_with("ipaddress", "${proxmox::hypervisor::cluster_master_ip}") { + #notify { "${::fqdn} will be the cluster master of ${proxmox::hypervisor::cluster_name}": } + + # Create the cluster on this node + exec { "Create ${proxmox::hypervisor::cluster_name} cluster on ${proxmox::hypervisor::cluster_master_ip}": + command => "pvecm create ${proxmox::hypervisor::cluster_name}", + onlyif => 'uname -r | grep -- "-pve"', + creates => '/etc/pve/cluster.conf', + } + } + else { + #notify { "${::fqdn} will be a cluster node of cluster ${proxmox::hypervisor::cluster_name}": } + + # Connect this node to the cluster + exec { "Connect to ${proxmox::hypervisor::cluster_name} cluster": + command => "pvecm add ${proxmox::hypervisor::cluster_master_ip}", + onlyif => 'uname -r | grep -- "-pve"', + creates => '/etc/pve/cluster.conf', + } + } + } + + + #notify { "Master IP: ${proxmox::hypervisor::cluster_master_ip} and Cluster name: ${proxmox::hypervisor::cluster_name}": } + +} # Private class: proxmox::hypervisor::cluster