| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 10 |
'status': ['preview'], |
| 11 |
'supported_by': 'community'} |
| 12 |
|
| 13 |
DOCUMENTATION = r''' |
| 14 |
--- |
| 15 |
module: intersight_ipmi_over_lan_policy |
| 16 |
short_description: IPMI over LAN Policy configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- Manages IPMI over LAN Policy configuration on Cisco Intersight. |
| 19 |
- A policy to configure the IPMI over LAN settings on Cisco Intersight managed servers. |
| 20 |
- IPMI over LAN allows management of servers using the IPMI protocol over Ethernet networks. |
| 21 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/ipmioverlan/Policy/get/). |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
state: |
| 25 |
description: |
| 26 |
- If C(present), will verify the resource is present and will create if needed. |
| 27 |
- If C(absent), will verify the resource is absent and will delete if needed. |
| 28 |
type: str |
| 29 |
choices: [present, absent] |
| 30 |
default: present |
| 31 |
organization: |
| 32 |
description: |
| 33 |
- The name of the Organization this resource is assigned to. |
| 34 |
- Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization. |
| 35 |
type: str |
| 36 |
default: default |
| 37 |
name: |
| 38 |
description: |
| 39 |
- The name assigned to the IPMI over LAN Policy. |
| 40 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 41 |
type: str |
| 42 |
required: true |
| 43 |
description: |
| 44 |
description: |
| 45 |
- The user-defined description for the IPMI over LAN Policy. |
| 46 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 47 |
type: str |
| 48 |
aliases: [descr] |
| 49 |
tags: |
| 50 |
description: |
| 51 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 52 |
type: list |
| 53 |
elements: dict |
| 54 |
enabled: |
| 55 |
description: |
| 56 |
- State of the IPMI Over LAN service on the endpoint. |
| 57 |
- Enable or disable IPMI over LAN functionality on the server. |
| 58 |
type: bool |
| 59 |
default: true |
| 60 |
privilege: |
| 61 |
description: |
| 62 |
- The highest privilege level that can be assigned to an IPMI session on a server. |
| 63 |
- This configuration is supported by all Standalone C-Series servers. |
| 64 |
- FI-attached C-Series servers with firmware at minimum of 4.2.3a support this configuration. |
| 65 |
- B/X-Series servers with firmware at minimum of 5.1.0.x support this configuration. |
| 66 |
- Privilege level 'user' is not supported for B/X-Series servers. |
| 67 |
type: str |
| 68 |
choices: ['admin', 'user', 'read-only'] |
| 69 |
default: 'admin' |
| 70 |
encryption_key: |
| 71 |
description: |
| 72 |
- The encryption key to use for IPMI communication. |
| 73 |
- It should have an even number of hexadecimal characters and not exceed 40 characters. |
| 74 |
- Use "00" to disable encryption key use. |
| 75 |
- This configuration is supported by all Standalone C-Series servers. |
| 76 |
- FI-attached C-Series servers with firmware at minimum of 4.2.3a support this configuration. |
| 77 |
- B/X-Series servers with firmware at minimum of 5.1.0.x support this configuration. |
| 78 |
- IPMI commands using this key should append zeroes to the key to achieve a length of 40 characters. |
| 79 |
type: str |
| 80 |
author: |
| 81 |
- Ron Gershburg (@rgershbu) |
| 82 |
''' |
| 83 |
|
| 84 |
EXAMPLES = r''' |
| 85 |
- name: Create IPMI over LAN Policy with encryption enabled |
| 86 |
cisco.intersight.intersight_ipmi_over_lan_policy: |
| 87 |
api_private_key: "{{ api_private_key }}" |
| 88 |
api_key_id: "{{ api_key_id }}" |
| 89 |
organization: "default" |
| 90 |
name: "IPMI-Policy-Encrypted" |
| 91 |
description: "IPMI over LAN policy with encryption" |
| 92 |
enabled: true |
| 93 |
privilege: "admin" |
| 94 |
encryption_key: "AB2134AC" |
| 95 |
tags: |
| 96 |
- Key: "Site" |
| 97 |
Value: "DataCenter-A" |
| 98 |
state: present |
| 99 |
|
| 100 |
- name: Create IPMI over LAN Policy with encryption disabled |
| 101 |
cisco.intersight.intersight_ipmi_over_lan_policy: |
| 102 |
api_private_key: "{{ api_private_key }}" |
| 103 |
api_key_id: "{{ api_key_id }}" |
| 104 |
organization: "default" |
| 105 |
name: "IPMI-Policy-No-Encryption" |
| 106 |
description: "IPMI over LAN policy without encryption" |
| 107 |
enabled: true |
| 108 |
privilege: "operator" |
| 109 |
encryption_key: "00" |
| 110 |
state: present |
| 111 |
|
| 112 |
- name: Create disabled IPMI over LAN Policy |
| 113 |
cisco.intersight.intersight_ipmi_over_lan_policy: |
| 114 |
api_private_key: "{{ api_private_key }}" |
| 115 |
api_key_id: "{{ api_key_id }}" |
| 116 |
name: "IPMI-Policy-Disabled" |
| 117 |
description: "Disabled IPMI over LAN policy" |
| 118 |
enabled: false |
| 119 |
state: present |
| 120 |
|
| 121 |
- name: Delete IPMI over LAN Policy |
| 122 |
cisco.intersight.intersight_ipmi_over_lan_policy: |
| 123 |
api_private_key: "{{ api_private_key }}" |
| 124 |
api_key_id: "{{ api_key_id }}" |
| 125 |
name: "IPMI-Policy-Encrypted" |
| 126 |
state: absent |
| 127 |
''' |
| 128 |
|
| 129 |
RETURN = r''' |
| 130 |
api_response: |
| 131 |
description: The API response output returned by the specified resource. |
| 132 |
returned: always |
| 133 |
type: dict |
| 134 |
sample: |
| 135 |
"api_response": { |
| 136 |
"Name": "IPMI-Policy-Encrypted", |
| 137 |
"ObjectType": "ipmioverlan.Policy", |
| 138 |
"Enabled": true, |
| 139 |
"Privilege": "admin", |
| 140 |
"IsEncryptionKeySet": true, |
| 141 |
"Tags": [ |
| 142 |
{ |
| 143 |
"Key": "Site", |
| 144 |
"Value": "DataCenter-A" |
| 145 |
} |
| 146 |
] |
| 147 |
} |
| 148 |
''' |
| 149 |
|
| 150 |
|
| 151 |
from ansible.module_utils.basic import AnsibleModule |
| 152 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 153 |
|
| 154 |
|
| 155 |
def validate_encryption_key(module): |
| 156 |
"""Validate the encryption key format""" |
| 157 |
encryption_key = module.params.get('encryption_key') |
| 158 |
if encryption_key and encryption_key != "00": |
| 159 |
# Check if it's a valid hex string |
| 160 |
try: |
| 161 |
int(encryption_key, 16) |
| 162 |
except ValueError: |
| 163 |
module.fail_json(msg="encryption_key must contain only hexadecimal characters") |
| 164 |
|
| 165 |
# Check if it has even number of characters |
| 166 |
if len(encryption_key) % 2 != 0: |
| 167 |
module.fail_json(msg="encryption_key must have an even number of characters") |
| 168 |
|
| 169 |
# Check if it doesn't exceed 40 characters |
| 170 |
if len(encryption_key) > 40: |
| 171 |
module.fail_json(msg="encryption_key must not exceed 40 characters") |
| 172 |
|
| 173 |
|
| 174 |
def main(): |
| 175 |
argument_spec = intersight_argument_spec.copy() |
| 176 |
argument_spec.update( |
| 177 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 178 |
organization=dict(type='str', default='default'), |
| 179 |
name=dict(type='str', required=True), |
| 180 |
description=dict(type='str', aliases=['descr']), |
| 181 |
tags=dict(type='list', elements='dict'), |
| 182 |
enabled=dict(type='bool', default=True), |
| 183 |
privilege=dict( |
| 184 |
type='str', |
| 185 |
choices=['admin', 'user', 'read-only'], |
| 186 |
default='admin' |
| 187 |
), |
| 188 |
encryption_key=dict(type='str', no_log=True) |
| 189 |
) |
| 190 |
module = AnsibleModule( |
| 191 |
argument_spec, |
| 192 |
supports_check_mode=True, |
| 193 |
) |
| 194 |
|
| 195 |
# Validate encryption key format |
| 196 |
validate_encryption_key(module) |
| 197 |
|
| 198 |
intersight = IntersightModule(module) |
| 199 |
intersight.result['api_response'] = {} |
| 200 |
intersight.result['trace_id'] = '' |
| 201 |
|
| 202 |
# Resource path used to configure policy |
| 203 |
resource_path = '/ipmioverlan/Policies' |
| 204 |
# Define API body used in compares or create |
| 205 |
intersight.api_body = { |
| 206 |
'Organization': { |
| 207 |
'Name': intersight.module.params['organization'], |
| 208 |
}, |
| 209 |
'Name': intersight.module.params['name'] |
| 210 |
} |
| 211 |
|
| 212 |
# In case state is absent we don't want to populate the api_body with any values |
| 213 |
if intersight.module.params['state'] == 'present': |
| 214 |
intersight.api_body['Enabled'] = intersight.module.params['enabled'] |
| 215 |
if intersight.module.params['enabled']: |
| 216 |
intersight.api_body['Privilege'] = intersight.module.params['privilege'] |
| 217 |
# Add encryption key if provided |
| 218 |
if intersight.module.params.get('encryption_key'): |
| 219 |
intersight.api_body['EncryptionKey'] = intersight.module.params['encryption_key'] |
| 220 |
|
| 221 |
intersight.set_tags_and_description() |
| 222 |
|
| 223 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 224 |
|
| 225 |
module.exit_json(**intersight.result) |
| 226 |
|
| 227 |
|
| 228 |
if __name__ == '__main__': |
| 229 |
main() |