waveclaw / puppet-subscription_manager

Handle Client Registration to RedHat Satellite 6 or Katello
https://rhn.redhat.com
Other
6 stars 34 forks source link

No resource and no name in property hash in subscription_manager instance #26

Closed pgassmann closed 8 years ago

pgassmann commented 8 years ago

Versions: RHEL 7.2 waveclaw-facter_cacheable (0.1.0) waveclaw-subscription_manager (2.0.0)

Situation: host was kickstarted with localhost.local and directly to rhn. Now I changed the hostname and want to attach it to a satellite. Plus, the new satellite is not yet reachable, it depends on vpn setup to be done first.

puppet resource --modulepath=./modules rhsm_register --debug --trace --evaltrace
....
Debug: Getting the registration settings as known to the system
Debug: Executing: '/usr/sbin/subscription-manager config --list'
Debug: Facter: searching for custom fact "rhsm_ca_name".
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/custom/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/stdlib/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/apt/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/staging/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/concat/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/firewall/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/facter_cacheable/lib/facter.
Debug: Facter: searching for rhsm_ca_name.rb in /root/pa-puppetconfig/modules/subscription_manager/lib/facter.
Info: Facter: loading custom facts from /root/pa-puppetconfig/modules/subscription_manager/lib/facter/rhsm_ca_name.rb.
Debug: Facter: fact "rhsm_ca_name" resolved to null and will not be added.
Debug: Facter: searching for custom fact "rhsm_identity".
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/custom/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/stdlib/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/apt/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/staging/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/concat/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/firewall/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/facter_cacheable/lib/facter.
Debug: Facter: searching for rhsm_identity.rb in /root/pa-puppetconfig/modules/subscription_manager/lib/facter.
Info: Facter: loading custom facts from /root/pa-puppetconfig/modules/subscription_manager/lib/facter/rhsm_identity.rb.
Debug: Facter: executing command: /usr/bin/sh -c /usr/sbin/subscription-manager identity
Debug: Facter: system identity: 0332e22c-9132-48da-958b-22fdc62edd5c
name: localhost.localdomain
org name: 7777819
org ID: 7777819
Debug: Facter: process exited with status code 0.
Debug: Facter: fact "rhsm_identity" has resolved to "0332e22c-9132-48da-958b-22fdc62edd5c".
#added for debugging:  pp registrations 
# after line 112  in modules/subscription_manager/lib/puppet/provider/rhsm_register/subscription_manager.rb
{:name=>nil,
 :identity=>"0332e22c-9132-48da-958b-22fdc62edd5c",
 :ensure=>:present}
Error: Could not run: No resource and no name in property hash in subscription_manager instance
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/provider.rb:534:in `name'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1171:in `block (2 levels) in instances'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1168:in `collect'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1168:in `block in instances'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1161:in `collect'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/type.rb:1161:in `instances'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/resource/ral.rb:24:in `search'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/indirection.rb:269:in `search'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/resource.rb:221:in `find_or_save_resources'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/resource.rb:136:in `main'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:352:in `run_command'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:344:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:540:in `exit_on_fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:344:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:128:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:72:in `execute'
/opt/puppetlabs/puppet/bin/puppet:5:in `<main>'
[root@eddie017 pa-puppetconfig]# /usr/sbin/subscription-manager config --list
[server]
   hostname = [subscription.rhn.redhat.com]
   insecure = [0]
   port = [443]
   prefix = [/subscription]
   proxy_hostname = []
   proxy_password = []
   proxy_port = []
   proxy_user = []
   ssl_verify_depth = [3]

[rhsm]
   baseurl = [https://cdn.redhat.com]
   ca_cert_dir = [/etc/rhsm/ca/]
   consumercertdir = [/etc/pki/consumer]
   entitlementcertdir = [/etc/pki/entitlement]
   full_refresh_on_yum = [0]
   manage_repos = [1]
   pluginconfdir = [/etc/rhsm/pluginconf.d]
   plugindir = [/usr/share/rhsm-plugins]
   productcertdir = [/etc/pki/product]
   repo_ca_cert = /etc/rhsm/ca/redhat-uep.pem
   report_package_profile = [1]

[rhsmcertd]
   autoattachinterval = [1440]
   certcheckinterval = [240]

[] - Default value in use
waveclaw commented 8 years ago

That will be a fundamentally unworkable case.

The registration's name is determined by the name of the Certificate Authority.

That fact reports nil, which appears correct for this case based on the evidence you provided. You do not appear to have a CA setup yet since you've are neither using an RHN certificate which would be detected nor a custom CA certificate.

Puppet cannot create an instance of a type that does not have a name. Furthermore any process of asking to connect to service that does not (yet) exist from the point of view of the client makes no sense.

So the subscription_manager module cannot be used for this case.

pgassmann commented 8 years ago

It should be possible to switch from RHN to a Satellite.

The Problem is, that the system does have an existing systemid (from rhn), but no rhsm_ca_name, because it is not yet attached to a satellite.

The solution would be to just define no rhsm_register instance if the rhsm_ca_name is not set, instead of failing.

Then it will be properly re-registered when using force => true

pgassmann commented 8 years ago

yet since you've are neither using an RHN certificate which would be detected nor a custom CA certificate.

The system has a valid subscription status with RHN. But because I define that it should be registered with rhsm, it runs the rhsm_register provider, which finds the systemid and then fails if there is no rhsm_ca_name set.

waveclaw commented 8 years ago

It would seem to me the best approach is to determine why no rhsm_ca_name is being generated from the valid subscription status with RHN.

Perhaps the free single-use RedHat Enterprise License will work for this test?

I would hope that even self-supported licenses can connect to RHN.

pgassmann commented 8 years ago

I found the root of the problem.

The format of the output of subscription_manager config --list is different than you expect. The values are in brackets if they do not differ from the default. as you can see in the output above.

I fixed the regular expression in the hostname query to allow the square brackets around the value:

  # What host are we configured to register to?
  # @return [String] the hostname of the Katello or Satellite service
  # or a nil if nothing
  # @api private
  def self.config_hostname
    host = nil
    config = subscription_manager(['config','--list'])
    config.split("\n").each { |line|
      if line =~ /hostname = \[?([a-z0-9.\-_]+)\]?/
        host = $1.chomp
      end
    }
    host
  end
waveclaw commented 8 years ago

As always, thanks for the help. Now I need to remind myself go recheck the other custom parsers just in case I missed the defaults case there, too.

While I'm at work I can comment here but I cannot do any work on this module. Sorry.