如何检查领班收集所有主人的事实

时间:2016-11-11 11:29:46

标签: puppet puppet-enterprise theforeman

想要编写自动化脚本以确保领班从所有节点收集事实

如何确保工头从所有节点获得事实?

1 个答案:

答案 0 :(得分:1)

事实是键/值数据对代表节点状态的某些方面,例如其IP地址,正常运行时间,操作系统或它是否是虚拟机。

<强> 1。手动流程为:

一个。登录工头用户界面,点击监控 - >事实

湾在主机上运行facter -p

<强> 2。自动化:    我写了下面的脚本来检查每个主机的事实

#!/usr/bin/python
import requests
import json

foreman_url = "https://foreman_ip/api/hosts"
username = "admin"
password = "changeme"
node = "node1.puppet.com"
headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
}    
def retrive_hostid():
  host_id = requests.get(foreman_url, headers=headers, verify=False, auth=(username, password))
  hostobj = json.loads(host_id.content)
  for s in hostobj:
     print s['host']['name']
     host_name = s['host']['name']
     url = foreman_url  + host_name + '/facts'  # check facts from each hosts
     print url
     response = requests.get(url, headers=headers, verify=False, auth=('admin', 'changeme'))
     #print response
     respobj = json.loads(response.content)
     print respobj['total'] # display total number of facts found

retrive_hostid()