Skip to content

Instantly share code, notes, and snippets.

@xtha
Created February 1, 2019 09:15
Show Gist options
  • Save xtha/1075f591d5a15eb8465e80a1e8d99002 to your computer and use it in GitHub Desktop.
Save xtha/1075f591d5a15eb8465e80a1e8d99002 to your computer and use it in GitHub Desktop.
ansible library
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
ipmi lan print:
IP Address Source : Static Address
IP Address : 10.144.128.215
Subnet Mask : 255.255.255.0
MAC Address : 6c:92:bf:32:e2:43
SNMP Community String : Inspur
IP Header : TTL=0x40 Flags=0x40 Precedence=0x00 TOS=0x10
BMC ARP Control : ARP Responses Enabled, Gratuitous ARP Disabled
Gratituous ARP Intrvl : 0.0 seconds
Default Gateway IP : 10.144.128.254
Default Gateway MAC : 00:00:00:00:00:00
Backup Gateway IP : 0.0.0.0
Backup Gateway MAC : 00:00:00:00:00:00
802.1q VLAN ID : Disabled
802.1q VLAN Priority : 0
ipmi fru list:
FRU Device Description : Builtin FRU Device (ID 0)
Chassis Type : Rack Mount Chassis
Chassis Part Number : 0
Chassis Serial : 00
Chassis Extra : NULL
Board Mfg Date : Fri Nov 21 01:22:00 2014
Board Mfg : Inspur
Board Product : YZMB-00370-109
Board Serial : 0
Board Part Number : SA5212M4
Product Manufacturer : Inspur
Product Name : SA5212M4
Product Part Number : 0
Product Version : 01
Product Serial : 816447059
Product Asset Tag : 816447059
'''
import re
import warnings
from ansible.module_utils.basic import AnsibleModule
try:
from pyghmi.ipmi import command, fru, sdr, bmc
HAS_PYGHMI = True
except ImportError:
HAS_PYGHMI = False
# Suppress warnings from hpilo
warnings.simplefilter('ignore')
def main():
module = AnsibleModule(
argument_spec = dict(
host = dict(required=True, type='str'),
login = dict(default='admin', type='str'),
password = dict(default='admin', type='str', no_log=True),
),
supports_check_mode=True,
)
if not HAS_PYGHMI:
module.fail_json(msg='The pyghmi python module is required')
host = module.params['host']
login = module.params['login']
password = module.params['password']
ipmi_cmd = command.Command(bmc=host, userid=login, password=password, port=623)
facts = dict()
fru_data = fru.FRU(ipmicmd=ipmi_cmd).info
facts['fru'] = { k.lower().replace(' ', '_'): v for k, v in fru_data.items()}
facts['bootdev'] = ipmi_cmd.get_bootdev()
facts['asset_tag'] = ipmi_cmd.get_asset_tag()
facts['netconf'] = ipmi_cmd.get_net_configuration()
facts['power'] = ipmi_cmd.get_power()
module.exit_json(ansible_facts=facts)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment