Don't post facts if there are none

Also, post non-facter facts - we have a hybrid system, why not report
all of our facts to puppetdb.

Change-Id: I246c5fd31739921d072edf8614c748dfaa611927
This commit is contained in:
Monty Taylor 2015-11-25 08:31:03 -05:00
parent d049384a82
commit f8c70cb1f2

View File

@ -92,21 +92,29 @@ def main():
for k, v in p['hostvars'].items(): for k, v in p['hostvars'].items():
if k.startswith('facter_'): if k.startswith('facter_'):
facts[k[7:]] = v facts[k[7:]] = v
payload = { for k, v in p['hostvars'].items():
"command": "replace facts", if not k.startswith('facter_'):
"version": 3, # Go ahead and set the non-facter facts that ansible has gathered
"payload": { # too - but let facter facts with the same name win
"name": fqdn, facts.setdefault(k, v)
"environment": p['environment'],
"producer-timestamp": timestamp,
"values": facts }}
r = requests.post(endpoint, json=payload, **requests_kwargs) if facts:
if r.status_code != 200: # Don't post facts update if we don't have facts
module.fail_json( payload = {
rc=r.status_code, "command": "replace facts",
msg="Failed to post facts to {puppetdb}".format( "version": 3,
puppetdb=p['puppetdb'])) "payload": {
"name": fqdn,
"environment": p['environment'],
"producer-timestamp": timestamp,
"values": facts }}
r = requests.post(endpoint, json=payload, **requests_kwargs)
if r.status_code != 200:
module.fail_json(
rc=r.status_code,
msg="Failed to post facts to {puppetdb}".format(
puppetdb=p['puppetdb']))
log_data = json.load(open(p['logfile'], 'r')) log_data = json.load(open(p['logfile'], 'r'))
r = requests.post(endpoint, json=log_data, **requests_kwargs) r = requests.post(endpoint, json=log_data, **requests_kwargs)