如何检查领班从所有主机收集事实



希望编写自动化脚本以确保foreman从所有节点收集事实

如何确保工头有来自所有节点的事实?

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

1。手工流程有:

。登录foreman UI,点击Monitor->Facts

b。run facter -p on hosts

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()

相关内容

  • 没有找到相关文章

最新更新