Class: CemAcpt::Provision::Linux

Inherits:
OsData
  • Object
show all
Defined in:
lib/cem_acpt/provision/terraform/linux.rb

Overview

Class provides methods for gathering provision data for Linux nodes

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary

Attributes inherited from OsData

#base_provision_directory

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OsData

#goss_files, #implementation_name, #initialize, #provision_directory, #puppet_manifest_file, #remote_module_package_name, use_for?

Methods included from Logging

current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?

Constructor Details

This class inherits a constructor from CemAcpt::Provision::OsData

Class Method Details

.valid_namesObject



9
10
11
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 9

def self.valid_names
  %w[centos rhel oel alma rocky ubuntu]
end

.valid_versionsObject



13
14
15
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 13

def self.valid_versions
  %w[7 8 9 2004 2204]
end

Instance Method Details

#destination_provision_directoryObject



25
26
27
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 25

def destination_provision_directory
  '/opt/cem_acpt'
end

#provision_commandsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 29

def provision_commands
  commands = [
    "sudo /opt/puppetlabs/puppet/bin/puppet module install #{destination_provision_directory}/#{remote_module_package_name}",
    'curl -fsSL https://goss.rocks/install | sudo sh',
    'sudo /opt/puppetlabs/puppet/bin/gem install webrick',
    'sudo chmod +x /opt/cem_acpt/log_service/log_service.rb',
    'sudo /opt/cem_acpt/log_service/log_service.rb',
  ]
  unless systemd_files.empty?
    systemd_files.each do |file|
      commands << "sudo cp /opt/cem_acpt/systemd/#{file} /etc/systemd/system/#{file}"
    end
    commands << 'sudo systemctl daemon-reload'
    systemd_files.each do |file|
      commands << "sudo systemctl start #{file} && sudo systemctl enable #{file}"
    end
  end

  commands << apply_command
end

#provision_commands_wrapper(image_name) ⇒ Object

A wrapper around provision_commands that allows for extra commands to be added for a specific OS version(i.e EL 8)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 51

def provision_commands_wrapper(image_name)
  if ['rhel-8', 'oel-8', 'alma-8', 'rocky-8'].any? { |el8| image_name.include?(el8) }
    commands = [
      'sudo dnf upgrade --refresh -y rpm glibc',
      'sudo rm /var/lib/rpm/.rpm.lock',
      'sudo dnf upgrade -y dnf',
    ]
    commands = (commands << provision_commands).flatten
    commands
  elsif image_name.include?('ubuntu')
    commands = ['sudo apt purge -y unattended-upgrades', 'sudo apt-get update -y']
    commands = (commands << provision_commands).flatten
    commands
  else
    provision_commands
  end
end

#puppet_bin_pathObject



21
22
23
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 21

def puppet_bin_path
  '/opt/puppetlabs/puppet/bin/puppet'
end

#systemd_filesObject



17
18
19
# File 'lib/cem_acpt/provision/terraform/linux.rb', line 17

def systemd_files
  Dir.glob(File.join(provision_directory, 'systemd', '*.service')).map { |f| File.basename(f) }
end