class profile::base {
include 'modules'
include '::profile::a'
}class role {
include 'profile::base'
}class role::test_server inherits ::role {
include '::profile::b'
}class profile::a {
if defined(File['/etc/test.txt']) {
$var = 'blah1.txt'
} else {
$var = 'blah2.txt'
}
File {$var :
ensure => file,
}
}class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
}
class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
before => Class['profile::a'],
}
class profile::b {
File { '/etc/test.txt' :
ensure => file,
owner => 'root',
group => 'root',
}
File['/etc/test.txt'] -> Class['profile::a']
}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']
}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']
}class profile::base {
include 'modules'
include '::profile::b'
include '::profile::a'
}class role::test_server inherits ::role {
include '::profile::b'
include '::profile::a'
}'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.
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.
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?