Philip Kirkbride
Philip Kirkbride

Reputation: 22859

Puppet ENC choose environment based on a fact?

I have an ENC setup which determines which environment a node will be placed during check-in.

Currently I'm keeping track of node types using the host name in an external database.

When a node checks in for the first time I'd like to determine the environment it should be in based on a fact. For example say I want to use the OS fact to determine if a new node should be sent a windows or linux configuration file.

It seems I only have access to the nodes host name, which I could potentially send to PuppetDB to retrieve the facts, but this wouldn't be the case on the initial check-in of a new node being registered with the Puppet Server.

Does anyone have a practical solution for this?

Upvotes: 0

Views: 506

Answers (1)

Philip Kirkbride
Philip Kirkbride

Reputation: 22859

I found that if I directly access PuppetDB from my ENC, even on the very first check in I could access all the facts for my node.

Here is an example ENC using a python library for PuppetDb use:

#!/usr/bin/env python

import sys
from pypuppetdb import connect

db = connect(host='puppetdb', port=8080, ssl_verify=False, ssl_key=None, ssl_cert=None, timeout=20)

certname = sys.argv[1]

try:
  node = db.node(certname)
  print 'environment: ' + node.fact('os').value
except:
  print 'environment: default'

Upvotes: 1

Related Questions