1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Support IPMI encryption key parameter in ipmi_boot (#3702)

* Support IPMI encryption key parameter in ipmi_boot

* Support py2 on hex parsing, error handling

Change parsing hex string to support python2 and add error handling to it based on feedback.

* Don't explicitly set required to false

* Add version_added to key arg

* Add changelog fragment

* Add IPMI encryption key arg to ipmi_power

* Fix the formatting of changelog fragment
This commit is contained in:
bluikko 2021-11-22 13:18:13 +07:00 committed by GitHub
parent 17c3708f31
commit 4013d0c9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 2 deletions

View file

@ -0,0 +1,4 @@
---
minor_changes:
- ipmi_boot - add support for user-specified IPMI encryption key (https://github.com/ansible-collections/community.general/issues/3698).
- ipmi_power - add support for user-specified IPMI encryption key (https://github.com/ansible-collections/community.general/issues/3698).

View file

@ -35,6 +35,12 @@ options:
- Password to connect to the BMC. - Password to connect to the BMC.
required: true required: true
type: str type: str
key:
description:
- Encryption key to connect to the BMC in hex format.
required: false
type: str
version_added: 4.1.0
bootdev: bootdev:
description: description:
- Set boot device to use on next reboot - Set boot device to use on next reboot
@ -115,11 +121,13 @@ EXAMPLES = '''
name: test.testdomain.com name: test.testdomain.com
user: admin user: admin
password: password password: password
key: 1234567890AABBCCDEFF000000EEEE12
bootdev: network bootdev: network
state: absent state: absent
''' '''
import traceback import traceback
import binascii
PYGHMI_IMP_ERR = None PYGHMI_IMP_ERR = None
try: try:
@ -138,6 +146,7 @@ def main():
port=dict(default=623, type='int'), port=dict(default=623, type='int'),
user=dict(required=True, no_log=True), user=dict(required=True, no_log=True),
password=dict(required=True, no_log=True), password=dict(required=True, no_log=True),
key=dict(type='str', no_log=True),
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
bootdev=dict(required=True, choices=['network', 'hd', 'floppy', 'safe', 'optical', 'setup', 'default']), bootdev=dict(required=True, choices=['network', 'hd', 'floppy', 'safe', 'optical', 'setup', 'default']),
persistent=dict(default=False, type='bool'), persistent=dict(default=False, type='bool'),
@ -162,10 +171,18 @@ def main():
if state == 'absent' and bootdev == 'default': if state == 'absent' and bootdev == 'default':
module.fail_json(msg="The bootdev 'default' cannot be used with state 'absent'.") module.fail_json(msg="The bootdev 'default' cannot be used with state 'absent'.")
try:
if module.params['key']:
key = binascii.unhexlify(module.params['key'])
else:
key = None
except Exception as e:
module.fail_json(msg="Unable to convert 'key' from hex string.")
# --- run command --- # --- run command ---
try: try:
ipmi_cmd = command.Command( ipmi_cmd = command.Command(
bmc=name, userid=user, password=password, port=port bmc=name, userid=user, password=password, port=port, kg=key
) )
module.debug('ipmi instantiated - name: "%s"' % name) module.debug('ipmi instantiated - name: "%s"' % name)
current = ipmi_cmd.get_bootdev() current = ipmi_cmd.get_bootdev()

View file

@ -35,6 +35,12 @@ options:
- Password to connect to the BMC. - Password to connect to the BMC.
required: true required: true
type: str type: str
key:
description:
- Encryption key to connect to the BMC in hex format.
required: false
type: str
version_added: 4.1.0
state: state:
description: description:
- Whether to ensure that the machine in desired state. - Whether to ensure that the machine in desired state.
@ -76,6 +82,7 @@ EXAMPLES = '''
''' '''
import traceback import traceback
import binascii
PYGHMI_IMP_ERR = None PYGHMI_IMP_ERR = None
try: try:
@ -95,6 +102,7 @@ def main():
state=dict(required=True, choices=['on', 'off', 'shutdown', 'reset', 'boot']), state=dict(required=True, choices=['on', 'off', 'shutdown', 'reset', 'boot']),
user=dict(required=True, no_log=True), user=dict(required=True, no_log=True),
password=dict(required=True, no_log=True), password=dict(required=True, no_log=True),
key=dict(type='str', no_log=True),
timeout=dict(default=300, type='int'), timeout=dict(default=300, type='int'),
), ),
supports_check_mode=True, supports_check_mode=True,
@ -110,10 +118,18 @@ def main():
state = module.params['state'] state = module.params['state']
timeout = module.params['timeout'] timeout = module.params['timeout']
try:
if module.params['key']:
key = binascii.unhexlify(module.params['key'])
else:
key = None
except Exception as e:
module.fail_json(msg="Unable to convert 'key' from hex string.")
# --- run command --- # --- run command ---
try: try:
ipmi_cmd = command.Command( ipmi_cmd = command.Command(
bmc=name, userid=user, password=password, port=port bmc=name, userid=user, password=password, port=port, kg=key
) )
module.debug('ipmi instantiated - name: "%s"' % name) module.debug('ipmi instantiated - name: "%s"' % name)