Ask Your Question
1

require not being honored between classes

asked 2013-05-14 16:39:17 -0500

rynop gravatar image

updated 2013-05-15 09:29:11 -0500

i have the following init.pp for my_module class:

class my_module ()
{   
    class{'my_module::install_dependencies': }

    class {'common_module::deploy::install':
      require => Class['my_module::install_dependencies'],
      before => Class['my_module::autoscale_deploy'],
    }           

    class{'my_module::autoscale_deploy':
      require => Class["common_module::deploy::install"]
    }
}

In 'common_module::deploy::install' I create a user like:

  user { "mydeployuser":
     ensure => 'present',
     managehome => 'true',
     password => '',
     home => '/home/mydeployuser',
     shell => '/bin/bash',
     comment => 'code deployer',
     provider => "useradd",
  }

In 'mymodule::autoscaledeploy' I create a new user and add him to the 'mydeployuser' group:

  user { "myuser":      #system user that JVM runs as
    name => "myuser",
    ensure => "present",
    provider => "useradd",
    groups => ['mydeployuser'],
    system => "true", 
  }

When I apply, I ... (more)

edit retag flag offensive close merge delete

Comments

In your last example where you declare class {'common_module::deploy::install': you have a require to the same class, so I you get a dependency cycle. You probably meant require => Class['my_module::install_dependencies']

Stefan gravatar imageStefan ( 2013-05-15 14:40:24 -0500 )edit

Yea I noticed that as well that the documented workaround in the issue had the same cycle, so I tried to change it to ::install_dependencies. This did not fix my ...(more)

rynop gravatar imagerynop ( 2013-05-16 08:23:00 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-05-14 16:50:10 -0500

Stefan gravatar image

Puppet has resource types for user and group (see http://docs.puppetlabs.com/references/latest/type.html for a reference list)

so when I see your user resource

user { "myuser":      #system user that JVM runs as
  name     => "myuser",
  ensure   => "present",
  provider => "useradd",
  groups   => ['mydeployuser'],
  system   => "true", 
}

I'd expect a group resource like

group { 'mydeployuser':
  ensure => present,
  gid    => '2000' # or don't specify gid if you don't care
}

but I do not see such a group resource in your manifest.

additional note: the provider and name attributes in the user resource are optional. If name is not set, it ... (more)

edit flag offensive delete link more

Comments

The group 'mydeployuser' is automatically created when the 'mydeployuser' user is added. If I add the group resource before creating myuser, the 'mydeployuser' add runs after it and I get ...(more)

rynop gravatar imagerynop ( 2013-05-14 17:02:09 -0500 )edit

ok get it now. The problem you are describing in your comment should be resolved in the next version (http://projects.puppetlabs.com/issues/19090). For your original problem: Is ...(more)

Stefan gravatar imageStefan ( 2013-05-14 17:11:08 -0500 )edit

Ah, that's a weird bug. Does explicitly defining the Group resource first work around it?

Ancillas gravatar imageAncillas ( 2013-05-14 17:15:43 -0500 )edit

mydeployuser is directly defined in common_module::deploy::install. Another reason I don't want to try and work around this with a group resource is I want to make sure ...(more)

rynop gravatar imagerynop ( 2013-05-14 18:06:10 -0500 )edit
0

answered 2013-05-14 16:50:16 -0500

Ancillas gravatar image

updated 2013-05-14 17:13:38 -0500

You're hitting a known bug. You need to use the Anchor Pattern to guarantee sub-class dependencies.

Also, as Stefan points out, you need to add a Group resource before your User resource.

EDIT

Try this.

class my_module ()
{   
  class {'my_module::install_dependencies': } ->
  class {'common_module::deploy::install': }  ->         
  class {'my_module::autoscale_deploy': }     ->
  Class['my_module']
}

class my_module::deploy::install ()
{
  user { "mydeployuser":
    ensure     => 'present',
    managehome => 'true',
    password   => '',
    home       => '/home/mydeployuser',
    shell      => '/bin/bash',
    comment    => 'code deployer',
    provider   => 'useradd',
  }
}

class my_module::autoscale_deploy ()
{
  user { 'myuser':
    name     => 'myuser',
    ensure   => 'present',
    provider => 'useradd',
    groups   => ['mydeployuser'],
    system   => 'true', 
  }
}
edit flag offensive delete link more

Comments

That was my firsst thought, too but that should only be true if the group resource was not defined in the common_module::deploy::install directly but in a nested class, right?

Stefan gravatar imageStefan ( 2013-05-14 16:53:40 -0500 )edit

Perhaps you're right. `Group['mydeployuser'] and User['mydeployuser'] are within Class['commonmodule::deploy::install'], and User['myuser'] is in Class['mymodule::autoscale_deploy'].

Ancillas gravatar imageAncillas ( 2013-05-14 17:03:19 -0500 )edit

The Class['my_module'] dependencies would wire up the class, but the resources within the classes would "float off". Since User['myuser'] is specifying a relationship with the Group, that should ...(more)

Ancillas gravatar imageAncillas ( 2013-05-14 17:05:21 -0500 )edit

Nope, the 'try this' edit example has the same problem. I think the arrow notation is just shorthand for before/require. I was not aware of the arrow notation however ...(more)

rynop gravatar imagerynop ( 2013-05-15 08:12:21 -0500 )edit

It's a pattern that R.I. came up with. The final dependency in the chain (the containing class itself) acts like a light-weight version of the anchor pattern. http://www.devco.net/archives/2012/12/13/simple-puppet-module-structure-redux.php

Ancillas gravatar imageAncillas ( 2013-05-15 11:18:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-14 16:39:17 -0500

Seen: 213 times

Last updated: May 15 '13