Repository: ansible-collections/community.general

Issue:
ipmi_* modules do not support specifying RCMP encryption key
### Summary

IPMI traffic may be encrypted with RCMP (RCMP+ of IPMI 2.0?) and IPMI BMCs provide a setting for this key. But the modules `ipmi_boot` and `ipmi_power` do not support user-specified encryption key.

The underlying python library `pyghmi` does support specifying the encryption key to the `Command` object:
```
    :param kg: Optional parameter to use if BMC has a particular Kg configured
```

This parameter should take the 128-bit encryption key usually specified as a hex string.

### Issue Type

Feature Idea

### Component Name

ipmi_boot

### Additional Information

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/remote_management/ipmi/ipmi_boot.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/remote_management/ipmi/ipmi_boot.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @bgaifullin @cloudnull
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/remote_management/ipmi/ipmi_boot.py b/plugins/modules/remote_management/ipmi/ipmi_boot.py
--- a/plugins/modules/remote_management/ipmi/ipmi_boot.py
+++ b/plugins/modules/remote_management/ipmi/ipmi_boot.py
@@ -35,6 +35,12 @@
       - 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 @@
     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()
diff --git a/plugins/modules/remote_management/ipmi/ipmi_power.py b/plugins/modules/remote_management/ipmi/ipmi_power.py
--- a/plugins/modules/remote_management/ipmi/ipmi_power.py
+++ b/plugins/modules/remote_management/ipmi/ipmi_power.py
@@ -35,6 +35,12 @@
       - 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 @@
 '''
 
 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)
 


Test patch: