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.
required: true
type: str
key:
description:
- Encryption key to connect to the BMC in hex format.
required: false
type: str
version_added: 4.1.0
bootdev:
description:
- Set boot device to use on next reboot
@ -115,11 +121,13 @@ EXAMPLES = '''
name: test.testdomain.com
user: admin
password: password
key: 1234567890AABBCCDEFF000000EEEE12
bootdev: network
state: absent
'''
import traceback
import binascii
PYGHMI_IMP_ERR = None
try:
@ -138,6 +146,7 @@ def main():
port=dict(default=623, type='int'),
user=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']),
bootdev=dict(required=True, choices=['network', 'hd', 'floppy', 'safe', 'optical', 'setup', 'default']),
persistent=dict(default=False, type='bool'),
@ -162,10 +171,18 @@ def main():
if state == 'absent' and bootdev == 'default':
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 ---
try:
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)
current = ipmi_cmd.get_bootdev()

View file

@ -35,6 +35,12 @@ options:
- Password to connect to the BMC.
required: true
type: str
key:
description:
- Encryption key to connect to the BMC in hex format.
required: false
type: str
version_added: 4.1.0
state:
description:
- Whether to ensure that the machine in desired state.
@ -76,6 +82,7 @@ EXAMPLES = '''
'''
import traceback
import binascii
PYGHMI_IMP_ERR = None
try:
@ -95,6 +102,7 @@ def main():
state=dict(required=True, choices=['on', 'off', 'shutdown', 'reset', 'boot']),
user=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'),
),
supports_check_mode=True,
@ -110,10 +118,18 @@ def main():
state = module.params['state']
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 ---
try:
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)