Skip to content

Instantly share code, notes, and snippets.

@parberge
Created October 18, 2017 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parberge/0f16a4158344826d492d43dcef104ff8 to your computer and use it in GitHub Desktop.
Save parberge/0f16a4158344826d492d43dcef104ff8 to your computer and use it in GitHub Desktop.
dynamic inventory snip
inventory = {
'all': {'hosts': []},
'baseline': {'hosts': []},
'signed_off': {'hosts': []},
'application_installation': {'hosts': []},
'operational_check': {'hosts': []},
'ansible': {'hosts': []},
'_meta': {'hostvars': {}},
}
for d in cmdb_connect.query(query=cmdb_query):
cmdb_data = d['server']
hostname = cmdb_data['hostname']
os = cmdb_data.get('os').get('type')
status = cmdb_data['status']
customer = cmdb_data.get('customer').get('servicetype')
patching = cmdb_data.get('services').get('patching')
logging.info('Processing host: %s', hostname)
logging.info("Adding to 'all' group")
inventory['all']['hosts'].append(hostname)
inventory['_meta']['hostvars'][hostname] = {
'os_version': cmdb_data.get('os').get('version'),
'ansible_host': cmdb_data.get('ip4').get('nic1').get('ip'),
'cmdb_status': status,
'cmdb_dnsname': cmdb_data.get('dnsname'),
'cmdb_patching_status': cmdb_data.get('services').get('patching'),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment