torrancew / hiera-foreman

A hiera backend that queries the Foreman for data
34 stars 15 forks source link

Feature: Cross node support #2

Open GregSutcliffe opened 12 years ago

GregSutcliffe commented 12 years ago

Presently I describe a cluster of machines with a YAML file that I load with Hiera. It looks something like:


---
servers:
  server1:
    type: loadbalancer
    ssl_cert: foo.example.com
  server2:
    type appserver
    apps:
      app1:
        threads: 2
        port: 3001
      app2:
        threads: 2
        port: 3002

I have puppet code which does things with the whole file. So for example, the loadbalancer needs to know about the appservers it is forwarding to. Presently I do this using some puppet code like:

$servers=hiera('servers')

file { 'my-nginx-loadbalancer': content => template('nginx/loadbalancer') }

and the template then uses Ruby and things like servers.map{} to get all of the apps and all of the ports and appserver names and write them out correctly. This is all fine (if hacky)

Now, I can easily add the data above to Foreman (so Host 'server2' could have a Parameter "app2 = 3001,2") and then it can be processed in the template but I cannot query that data from the loadbalancer, as the code looks directly to $fqdn.

In all honesty, I probably need to remodel my puppet code (it's hacky, I agree) but the idea of querying wider Foreman data seemed useful, so I'm throwing it out there.

torrancew commented 12 years ago

Wow, that's some spaghetti config management ;)

I'm open to the idea, though I'll admit I'm still having a hard time wrapping my head around the whole scenario. I do hope to add this, but it's going to take a backseat to #1 in the mean time.

GregSutcliffe commented 12 years ago

Yeah, I know. It was because foreman 1.0 can't really store complex YAML yet, so we ended up describing the whole cluster in one go. I would like to maybe break it down and add all the server specific data to Foreman and then use the foreman.rb lookup function to get, say, all the nodes in the same environment and which are appservers. This would be a nice halfway house as it would still use hiera :)

So, forget my crazy-ass-needing-refactor code, and we can revisit the idea of generally asking question of Foreman in a hiera-style way later. If we get this right, we can probably drop the foreman.rb function entirely :)

torrancew commented 12 years ago

@GregSutcliffe - I just pushed a smartvar_queries branch that adds a few public helper methods :

def lookup_enc(fqdn)
def lookup_smartvars(fqdn)

That branch should also fix calls from within puppet modules. I'd love your feedback on how it addresses #1 and #4, but it may also help you wire up something for your current dilemma (maybe create a new puppet function, or similar). We can also see about making this work more the way you had in mind down the road.