I have a question about the ordering of includes.....
# puppet
j
I have a question about the ordering of includes.. or the prioritization of classes in Puppet. I’ll include details in a follow up to this thread. I’ve been using the software for over 10 years, and I hadn’t had a problem until I believe an upgrade took away defaults. The basic problem is that I have one class that defines hosts, and another that sets up firewall rules. It used to be that the hosts would run first, then the firewall rules.. but now it’s that the puppet agent won’t run if a new host is added, because the firewall rules are running first
so, basically I have the nodes defined as follows:
Copy code
node /^app\d+/ {
  include hosts
  include firewall
}
with the hosts.pp looking like:
Copy code
class hosts {
  host { 'app01':
    ip => 'x.x.x.x'
  }
...
and the firewall something like:
Copy code
class firewall {
  package { ['iptables-services']: 
    ensure => installed 
  }
  package { ['firewalld']: 
    ensure => absent 
  }
  
  firewall { '200 allow Service':
    source => 'app01',
    dport => 'xxx',
    proto => 'tcp',
    action => 'accept'
  }
...
this is all simplified.. but basically, I want the hosts to run before the firewall rules, in case a new app server is added. I have tried renaming hosts to be ahosts so that it would come alphabetically before firewall.. but I’m not sure how the ensure that the hosts class has been parsed before the firewall is. I may also not be understanding how puppet works, and this could be leading to my confusion 😄
I also tried out variations of Class[hosts] -> Class[firewall] but couldn’t get it to work
b
• there's a thing called DNS servers 😛 •
Class['hosts'] -> Class['firewall']
looks correct (notice the single quotes)
why is that ordering important?
does iptables rely on the DNS lookup while you create the rule?
(don't use DNS names in firewall rules)
j
lol true, I could set up a DNS server, or use our DNS server.. but this is all internal stuff..
b
DNS works also internally
and it's a ton easier than maintaining /etc/hosts entries
j
yeah, iptables is running first and trying to lookup the name, but failing. the iptables rules are running first.. and we’re using names so that we can swap hosts in and out when needed, without needing to reference back to which IP goes with which host
well, puppet does manage the host file entries 😄
I’ll check out the class chaining.. I’ve got one new server ready, and I’ll be adding another 5 shortly, so I want to work this out.. should that rule be at the top of the hosts class?
b
you do that in your node block or you do a
require hosts
in the firewall class
j
okay thanks, I’ll try that out right now
hrmm I tried a bunch out, and it doesn’t seem to affect anything.. currently, I have:
Copy code
class firewall::init {
  Class['hosts'] -> Class['firewall::init']
  require Class['hosts']
  require hosts
b
now what is firewall::init?
j
ahh yeah, there’s actually firewall rules per service, depending on what services the server is running.. but everything starts with firewall:init and ends with firewall:fini
currently, it is failing while parsing the rules for firewall::init however
b
can you show the agent output?
j
Copy code
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Notice: Requesting catalog from puppet:8140 (x.x.x.x)
Notice: Catalog compiled by puppet
Error: Failed to apply catalog: Parameter source failed on Firewall[007 allow monitoring SNMP]: Munging failed for value "new-server" in class source: host_to_ip failed for new-server, exception Failed to resolve hostname new-server (file: /etc/puppetlabs/code/environments/production/manifests/classes/firewall.pp, line: 49)
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
b
Mhm
That path to the firewall.pp looks odd
That's not the firewall::init class, is it?
j
all of the firewall rules/classes are in the same file
it hasn’t been a problem in the past, but I have been dragging around this configuration for a decade 😄
b
That should heavily confuse the autoloading.
Wait
Classes?
Plural?
Do you have multiple classes in that file?
j
yup
b
Jesus
🙏 1
Can You show the whole class?
Eh, the whole file
I think you are ordering the wrong classes
And puppet-lint would puke on that style. It might work, but it's highly unusual and makes debugging more complex
@csharpsteen ^ maybe you are interested in this setup
donotwant 1
If it works for you, it ain't bad. But I guess You don't do any linting or unit testing?
j
well, it has seemed to work.. I can split the init into a different file and see if that makes a difference?
as for sharing the file, I’d rather not expose that information, but I can give an overview 😄
b
What's in line 49 and is that within the firewall::init class or something else?
j
yup
c
In general, this sounds like missing dependencies between resources.
contain()
might help if these are grouped up in a profile class.
j
hrmm I tried out a couple of things and didn’t get any further.. I tried this out, for instance:
Copy code
class firewall {
  contain firewall::init
}
is that what you were talking about?
b
Giving recommendations for correct ordering is a challenge without knowing what those classes do and how many classes you have
j
so, in the firewall.pp, there are a bunch of classes that just setup the firewall rules for the servers to communicate with each other, so there are these classes: • firewall::init • firewall::db • firewall:db:staging • firewall::app • firewall::rabbitmq • firewall::fini
it is 1000k long, so it isn’t a bad idea to split it up.. is the directory syntax like:
Copy code
/manifests/classes/firewall/init.pp
/manifests/classes/firewall/db.pp
/manifests/classes/firewall/staging/db.pp
...
b
Or!
You split it into an actual module that's testable
j
lol sorry, I misspoke, it’s 1k lines long.. getting late here 😄