Description
I am unable to get class 'profile::b' to run before class 'profile::a'.
Setup
I have two classes that create files, class 'profile::a' and class
'profile::b'.
I am following the roles and profiles setup. I have a base profile where I
am including 'profile::a':
class profile::base {
include 'modules'
include '::profile::a'
}
Then I have a class role include the base profile
class role {
include 'profile::base'
}
And then I have our server roles inherit role:
class role::test_server inherits ::role {
include '::profile::b'
}
'profile::a'
class profile::a {
if defined(File['/etc/test.txt']) {
$var = 'blah1.txt'
} else {
$var = 'blah2.txt'
}
File {$var :
ensure => file,
}
}
'profile::b'
class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
}
Problem
'profile::a' should be applied to every server and 'profile::b' is only
being applied to a few servers. My understanding of resource chaining is
that I can alter the order in which the classes are ran. I need "b" to run
first so that I can key off of "defined(File['/etc/test/txt']).
I have tried multiple approaches and I cannot get this to work.
#1
class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
before => Class['profile::a'],
}
#2
class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
}
File['/etc/test.txt'] -> Class['profile::a']
}
#3
class profile::a {
if defined(File['/etc/test.txt']) {
$var = 'blah1.txt'
} else {
$var = 'blah2.txt'
}
File {$var :
ensure => file,
}
File['/etc/test.txt'] -> Class['profile::a']
}
#4
class profile::a {
if defined(File['/etc/test.txt']) {
$var = 'blah1.txt'
} else {
$var = 'blah2.txt'
}
File {$var :
ensure => file,
}
File<| title == '/etc/test.txt' |> -> Class['profile::a']
}
The only way that it works is if I explicitly include 'profile::b' before
'profile::a' in base.
class profile::base {
include 'modules'
include '::profile::b'
include '::profile::a'
}
Or if I remove 'profile::a' from base and include them both in the role.
class role::test_server inherits ::role {
include '::profile::b'
include '::profile::a'
}
I have alternatives. I can set values in hiera to key off of or push out
custom facts. Custom facts will not be there on the first run which is
probably ok. I think we would run into a few issues here and there but I
could make it work. I could set hiera vars and key off of those instead but
with our hiera setup that would require duplicating a lot of code across
every role.
Everything I have read says that chaining the resource should enforce the
order but I am obviously missing something. Can someone see what I am doing
wrong or explain why this will not work?
Thank you in advance.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/ce3039c8-0c9b-4fc1-b5d6-2e04c80396d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.