Failed to realize virtual resources

2,257 views
Skip to first unread message

S L

unread,
Mar 28, 2014, 11:38:30 AM3/28/14
to puppet...@googlegroups.com
i've moduiles/virtualuser/manifests/init.pp

class virtualuser ( $allusers = hiera('users'))
{
  include virtualuser::virtual
  $allusers.each |$key,$value|
  {
    #not showing code to extract all variables from hiera
 
    if $virtual == true {
        @virtualuser::virtual::localuser { $key:
          key        => $key,
          value      => $value,
          gid        => $gid,
          uid        => $uid,
          homedir    => $homedir,
          expire     => $expire,
          ensure     => $ensure,
          shell      => $shell,
          groups     => $groups,
          password   => $password,
          managehome => $managehome,
          system     => $system,
          managekeys => $managekeys
        }
    }
}

same dir i've puppet class virtual.pp

class virtualuser::virtual
{
  define localuser ($key,$value,$gid,$uid,$homedir,$expire,$ensure,$shell,$groups,$password,$managehome,$system,$managekeys)
  {
    #create or remove virtual user
    group { $key:
     ensure => $ensure,
     tag    => 'allgroups',
     gid    => $gid,
    }

    user { $key:
      ensure     => $ensure,
      shell      => $shell,
      uid        => $uid,
      allowdupe  => false,
      expiry     => $expire,
      gid        => $gid,
      groups     => $groups,
      password   => $password,
      managehome => $managehome,
      home       => $homedir,
      tag        => 'allusers',
    }

    file { "$homedir":
        ensure => directory,
        mode   => 700,
        owner  => $key,
        group  => $key
      }

      file { "$homedir/.ssh":
        ensure => directory,
        mode   => 700,
        owner  => $key,
        group  => $key,
        tag    => 'sshdir',
      }

in another puppet class,  i try to realize a user

   realize (Virtualuser::Virtual::Localuser['virtualuser'])


and Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to realize virtual resources Virtualuser::Virtual::Localuser[virtualuser] on node n1.xx

Please help!  Its been 4 days I'm struggling to get this working.

SL

José Luis Ledesma

unread,
Mar 28, 2014, 1:40:45 PM3/28/14
to puppet...@googlegroups.com

From http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html

Type definitions may also be placed inside class definitions; however, this limits their availability to that class and is not recommended for any purpose. This is not formally deprecated in this version of Puppet, but may become so in a future release.

--------

I think the problem is this, you should  put the define in
modules/virtualuser/manifests/virtual/localuser.pp

Obv outside any class.

Regards,

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/90c5032b-8e2d-468a-a159-32c926c3684d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

S L

unread,
Mar 28, 2014, 8:04:16 PM3/28/14
to puppet...@googlegroups.com
Thanks. But that did not help.  Here is my new code:

modules/virualuser/manifests/
init.pp

class virtualuser( $allusers = hiera('users'))
{
  $allusers.each |$key,$value|
  {
      #code to extract hiera variables not shown

      if $virtual == true {
        @virtualuser::addvirtualuser { $key:

          key        => $key,
          value      => $value,
          gid        => $gid,
          uid        => $uid,
          ..................
      }
}

The following define is currently within the same file (but outside of class definition) as above (virtualuser/manifests/init.pp),  I've also tried to create a separate localuser.pp file and still got the same error

define virtualuser::addvirtualuser($key,$value,$gid,$uid,$homedir,$expire,$ensure,$shell,$groups,$password,$managehome,$system,$managekeys)

{
 #create or remove virtual user
    group { $key:
     ensure => $ensure,
     tag    => 'allgroups',
     gid    => $gid,
    }

    user { $key:
      ensure     => $ensure,
      shell      => $shell,
   ..............
   .........
    }
}

- realize is being called in init.pp of a puppet class on a different node

realize(Virtualuser::Addvirtualuser['virtualfoo'])

same error message:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to realize virtual resources Virtualuser::Addvirtualuser[virtualfoo] on node xx.yy


I'm surprised there is no better way to debug this problem.

José Luis Ledesma

unread,
Mar 29, 2014, 2:50:42 AM3/29/14
to puppet...@googlegroups.com

Well, the define has changed its name, the file should be named addvirtualuser.pp to enable the autoloader load it. Anyway if it is in the same init.pp it should work.

Are you sure the class virtualuser is included ?  Are you sure $virtual is true? I am not sure about that, but I think you should include the virtualuser class before any class that wants to realize

I would set a couple of notifies in the virtual user class and in the define to check if it I'd behaving correctly.

Also you can try to call the define without virtualizing it to check if it works.

Regards,

Edward Ned Harvey

unread,
Jun 23, 2021, 2:44:35 PM6/23/21
to Puppet Users
Hi slpas...

I realize it's 7 years later, but I'm struggling to do exactly what you were talking about back then. What was your solution? Could you post working code? Thanks.
Reply all
Reply to author
Forward
0 new messages