# profiles::minio::server class profiles::minio::server ( String $minio_root_user, String $minio_root_pass, Array $minio_opts = [], Boolean $minio_members_lookup = false, String $minio_members_role = undef, Integer $minio_members = undef, Array $minio_servers = [], String $minio_storage_class = 'EC:2', String $version = 'RELEASE.2023-12-20T01-00-02Z', String $checksum = '09fafaf399885b4912bafda6fa03fc4ccbc39ec45e17239677217317915d6aeb', String $checksum_type = 'sha256', String $owner = 'minio', String $group = 'minio', Stdlib::Fqdn $url_domain = $::facts['networking']['domain'], Enum['http', 'https'] $url_scheme = 'http', Array[String[0]] $blockdev = [], Stdlib::Port $listen_port = 9000, Stdlib::IP::Address $listen_addr = $::facts['networking']['ip'], Stdlib::AbsolutePath $datadir = '/data/minio', Stdlib::AbsolutePath $confdir = '/etc/minio', Stdlib::AbsolutePath $homedir = '/var/lib/minio', Stdlib::AbsolutePath $bindir = '/opt/minio', Optional[Enum['puppet']] $cert_type = 'puppet', ) { # create the region string $minio_region = "${::facts['country']}-${::facts['region']}" # count the block devices $blockdev_count = count($blockdev) # create minio static facts, which are used by pre-compile facts file { "${lookup('facts_path')}/minio_facts.yaml": ensure => file, content => template('profiles/minio/minio_facts.yaml.erb'), } # create the user if its not yet initialised, if it is initialised, let the minio::server class manage # manage the resource. This is done so that the user/group exist before attempting to create the data- # directories. if ! $::facts['minio_user_exists'] { class {'minio::server::user': manage_user => true, manage_group => true, manage_home => true, owner => $owner, group => $group, home => $homedir, } } # create the datadir if ! $::facts['minio_datadirs_initialised'] { # create the datadir root exec { "mkdir_p_${datadir}": command => "mkdir -p '${datadir}'", unless => "test -d '${datadir}'", path => '/bin:/usr/bin', } # create te datavol's if blockdev's are listed $blockdev.each |Integer $index, String $device| { $id = $index + 1 profiles::storage::datavol {"${::facts['networking']['fqdn']}_${device}": fstype => 'xfs', vg => "minio_vg${id}", pv => $device, lv => "store${id}", owner => $owner, group => $group, mount => "${datadir}/store${id}", require => Exec["mkdir_p_${datadir}"], } } } # copy puppet certs to /etc/pki/tls/puppet include profiles::pki::puppetcerts # create the cert configuration hash if $cert_type == 'puppet' { $cert_conf = { 'source_path' => '/etc/pki/tls/puppet', 'source_cert_name' => $::facts['networking']['fqdn'], 'source_key_name' => $::facts['networking']['fqdn'], } } # if lookup is enabled, find all the hosts in the specified role and create the servers_array if $minio_members_lookup { # check that the role is also set unless !($minio_members_role == undef) { fail("minio_members_role must be provided for ${title} when minio_members_lookup is True") } # if it is, find hosts, sort them so they dont cause changes every run #$servers_array = sort(query_nodes("enc_role='${minio_members_role}'", 'networking.fqdn')) $servers_array = sort(query_nodes("enc_role='${minio_members_role}' and minio_region='${minio_region}'", 'networking.fqdn')) # else use provided array from params }else{ $servers_array = $minio_servers } # iterate through the servers_array and find the nodeid for each host $servers_array.each |Integer $index, String $server| { $id = $index + 1 if $::facts['networking']['fqdn'] == $server { $nodeid = $id if $::facts['minio_pool'] != undef { # create a cname which is used to create a sequential group of names for distributed minio pool profiles::dns::record { "${minio_region}-${::facts['minio_pool']}-${nodeid}.${::facts['networking']['domain']}_CNAME": value => $::facts['networking']['hostname'], type => 'CNAME', record => "${minio_region}-${::facts['minio_pool']}-${nodeid}.${::facts['networking']['domain']}.", zone => $::facts['networking']['domain'], order => 10, } } } } # wait until all expected servers in the pool have reported into puppet if count($servers_array) == $::facts['minio_members'] and $::facts['minio_pool'] != undef { # if datadirs and user have been initialised, prepare configuration. if $::facts['minio_datadirs_initialised'] and $::facts['minio_user_exists'] { # join the minio_opts $options = join($minio_opts, ' ') # create vars for $deployment_definition, others used below are params $url_location = "${minio_region}-${::facts['minio_pool']}" $url_servers = "1...${count($servers_array)}" # create the deployment definition line # >= 1 : https://au-somewhere-1-pool1-{1...5}.example.domain/var/minio/store{1...4} # == 1 : https://au-somewhere-1-pool1-{1...5}.example.domain/var/minio/store1 # else : https://au-somewhere-1-pool1-{1...5}.example.domain/var/minio if $blockdev_count >= 1 { $deployment_definition = "${url_scheme}://${url_location}-{${url_servers}}.${url_domain}:${listen_port}${datadir}/store{1...${blockdev_count}}" }elsif $blockdev_count == 1 { $deployment_definition = "${url_scheme}://${url_location}-{${url_servers}}.${url_domain}:${listen_port}${datadir}/store1" }else{ $deployment_definition = "${url_scheme}://${url_location}-{${url_servers}}.${url_domain}:${listen_port}${datadir}" } # create the configuration hash $configuration = { 'MINIO_ROOT_USER' => $minio_root_user, 'MINIO_ROOT_PASSWORD' => $minio_root_pass.unwrap, 'MINIO_REGION_NAME' => $minio_region, 'MINIO_OPTS' => "\'${options}\'", 'MINIO_DEPLOYMENT_DEFINITION' => $deployment_definition, 'MINIO_STORAGE_CLASS_STANDARD' => $minio_storage_class, } } } # check all the expected DNS CNAME records do not exist $all_dns_exist = $::facts['minio_pool_dns'].all |String $cname, Boolean $exists| { $exists } # create the minio server if all dns records exist if $all_dns_exist { class { 'minio::server::install': package_ensure => 'present', owner => $owner, group => $group, base_url => 'https://dl.minio.io/server/minio/release', version => $version, checksum => $checksum, checksum_type => $checksum_type, configuration_directory => $confdir, installation_directory => $bindir, storage_root => $datadir, listen_ip => $listen_addr, listen_port => $listen_port, manage_service => true, service_template => 'profiles/minio/minio.service.erb', service_provider => 'systemd', cert_directory => "${confdir}/certs", custom_configuration_file_path => '/etc/default/minio', } class { 'minio::server::config': owner => $owner, group => $group, configuration_directory => $confdir, installation_directory => $bindir, storage_root => $datadir, configuration => $configuration, custom_configuration_file_path => '/etc/default/minio', require => Class['Minio::Server::Install'], } class { 'minio::server::service': manage_service => true, service_provider => 'systemd', service_ensure => 'running', require => Class['Minio::Server::Config'], } } }