Ask Your Question
1

How can I enforce relationship ordering for Users and Groups which are Virtual Resources?

asked 2015-04-17 18:13:35 -0600

updated 2015-04-17 19:16:16 -0600

I would like to manage Users and Groups using Virtual Resources. On my Linux system, I must create the user group before I create users which are members of that group. This is normally resolved using resource ordering ("resource chaining").

How can I use resource ordering enforce the order for these user and group virtual resources?

For example, the using the standard require or subscribe directives will fail:

# test.pp
@group { 'admins':
  ensure => 'present',
}

@user { 'joe':
  ensure  => 'present',
  groups  => ['admins'],
  require => Group['admins'],
}

@user { 'jane':
  ensure  => 'present',
  groups  => ['admins'],
  require => Group['admins'],
}

realize User['joe']
realize User['jane']


$ puppet apply --modulepath=. --noop test.pp
Notice: Compiled catalog for puppet.example.org in environment production in 0.34 seconds
Error: Could not find dependency Group[admins] for User[joe] at .../manifests/test.pp:9
$
edit retag flag offensive close merge delete

Comments

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-04-17 20:15:24 -0600

ramindk gravatar image

updated 2015-04-19 14:44:19 -0600

You have to realize the group as well.

realize Group['admins']

Something like the following may also work in some cases, but will easily trip up someone who does not understand what the code does. It would be better to move users and group into Hiera.

test.pp

@group { 'admins':
  ensure => 'present',
  tag    => 'admins',
}

@user { 'joe':
  ensure  => 'present',
  groups  => ['admins'],
  require => Group['admins'],
  tag     => 'admins',
}

@user { 'jane':
  ensure  => 'present',
  groups  => ['admins'],
  require => Group['admins'],
  tag     => 'admins',
}

# this line will realize and set order.
# It is a bit magical and will realize all matching resources.
# https://docs.puppetlabs.com/puppet/latest/reference/lang_virtual.html#realizing-with-a-collector
Group<| tag == 'admins' |> -> User<| tag == 'admin' |>

Attempting to chain realize statements generates errors. I'd guess that's because realize is a function rather than a resource. Same reason you can chain class { someclass: } and not include class.

edit flag offensive delete link more

Comments

Thanks for that answer. Is it possible for me to realize the virtual @group inside of a @user virtual class? I know that I can `realize Group['admins']` outside of my class, but that doesn't do the resource changing that I was expecting to have.

stefanlasiewski gravatar imagestefanlasiewski ( 2015-04-19 14:17:39 -0600 )edit

If I can chain real resources, can't I chain virtual resources in the same manner?

stefanlasiewski gravatar imagestefanlasiewski ( 2015-04-19 14:17:47 -0600 )edit

Updated answer as to why you can not chain realize. I'm not sure I understand your first questions, but you should be able to throw a realize anywhere you need it assuming you're including the classes.

ramindk gravatar imageramindk ( 2015-04-19 14:46:51 -0600 )edit

Please disregard my first question, I had oversimplified my example here; and thus the question doesn't really make sense.

stefanlasiewski gravatar imagestefanlasiewski ( 2015-04-22 18:04:42 -0600 )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

1 follower

Stats

Asked: 2015-04-17 18:13:35 -0600

Seen: 557 times

Last updated: Apr 19 '15