class Chef::Resource::RhsmRegister

Public Instance Methods

ca_consumer_package_source() click to toggle source

@return [String] The URI to fetch katello-ca-consumer-latest.noarch.rpm from

# File lib/chef/resource/rhsm_register.rb, line 191
def ca_consumer_package_source
  protocol = new_resource.https_for_ca_consumer ? "https" : "http"
  "#{protocol}://#{new_resource.satellite_host}/pub/katello-ca-consumer-latest.noarch.rpm"
end
flush_package_cache_name() click to toggle source

@return [String]

# File lib/chef/resource/rhsm_register.rb, line 163
def flush_package_cache_name
  "rhsm_register-#{new_resource.name}-flush_cache"
end
katello_cert_rpm_installed?() click to toggle source

@return [Boolean] is katello-ca-consumer installed

# File lib/chef/resource/rhsm_register.rb, line 184
def katello_cert_rpm_installed?
  shell_out("rpm -qa").stdout.include?("katello-ca-consumer")
end
package_resource() click to toggle source

@return [Symbol] dnf_package or yum_package depending on OS release

# File lib/chef/resource/rhsm_register.rb, line 170
def package_resource
  node["platform_version"].to_i >= 8 ? :dnf_package : :yum_package
end
register_command() click to toggle source
# File lib/chef/resource/rhsm_register.rb, line 196
def register_command
  command = %w{subscription-manager register}

  if new_resource.activation_key
    unless new_resource.activation_key.empty?
      raise "Unable to register - you must specify organization when using activation keys" if new_resource.organization.nil?

      command << new_resource.activation_key.map { |key| "--activationkey=#{Shellwords.shellescape(key)}" }
      command << "--org=#{Shellwords.shellescape(new_resource.organization)}"
      command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name
      command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url
      command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url
      command << "--release=#{Shellwords.shellescape(new_resource.release)}" if new_resource.release
      command << "--force" if new_resource.force

      return command.join(" ")
    end
  end

  if new_resource.username && new_resource.password
    raise "Unable to register - you must specify environment when using username/password" if new_resource.environment.nil? && using_satellite_host?

    if new_resource.service_level
      raise "Unable to register - 'auto_attach' must be enabled when using property `service_level`." unless new_resource.auto_attach
    end

    if new_resource.release
      raise "Unable to register - `auto_attach` must be enabled when using property `release`." unless new_resource.auto_attach
    end

    command << "--username=#{Shellwords.shellescape(new_resource.username)}"
    command << "--password=#{Shellwords.shellescape(new_resource.password)}"
    command << "--environment=#{Shellwords.shellescape(new_resource.environment)}" if using_satellite_host?
    command << "--name=#{Shellwords.shellescape(new_resource.system_name)}" if new_resource.system_name
    command << "--serverurl=#{Shellwords.shellescape(new_resource.server_url)}" if new_resource.server_url
    command << "--baseurl=#{Shellwords.shellescape(new_resource.base_url)}" if new_resource.base_url
    command << "--auto-attach" if new_resource.auto_attach
    command << "--servicelevel=#{Shellwords.shellescape(new_resource.service_level)}" if new_resource.service_level
    command << "--release=#{Shellwords.shellescape(new_resource.release)}" if new_resource.release
    command << "--force" if new_resource.force

    return command.join(" ")
  end

  raise "Unable to create register command - you must specify activation_key or username/password"
end
registered_with_rhsm?() click to toggle source

@return [Boolean] is the node registered with RHSM

# File lib/chef/resource/rhsm_register.rb, line 177
def registered_with_rhsm?
  @registered ||= !shell_out("subscription-manager status").stdout.include?("Overall Status: Unknown")
end
using_satellite_host?() click to toggle source
# File lib/chef/resource/rhsm_register.rb, line 243
def using_satellite_host?
  !new_resource.satellite_host.nil?
end