mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
|
@ -0,0 +1,203 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2018 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: idrac_redfish_command
|
||||
short_description: Manages Out-Of-Band controllers using iDRAC OEM Redfish APIs
|
||||
description:
|
||||
- Builds Redfish URIs locally and sends them to remote OOB controllers to
|
||||
perform an action.
|
||||
- For use with Dell iDRAC operations that require Redfish OEM extensions
|
||||
options:
|
||||
category:
|
||||
required: true
|
||||
description:
|
||||
- Category to execute on OOB controller
|
||||
type: str
|
||||
command:
|
||||
required: true
|
||||
description:
|
||||
- List of commands to execute on OOB controller
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of OOB controller
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- User for authentication with OOB controller
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with OOB controller
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to OOB controller
|
||||
default: 10
|
||||
type: int
|
||||
resource_id:
|
||||
required: false
|
||||
description:
|
||||
- The ID of the System, Manager or Chassis to modify
|
||||
type: str
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create BIOS configuration job (schedule BIOS setting update)
|
||||
idrac_redfish_command:
|
||||
category: Systems
|
||||
command: CreateBiosConfigJob
|
||||
resource_id: System.Embedded.1
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
msg:
|
||||
description: Message with action result or error description
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Action was successful"
|
||||
'''
|
||||
|
||||
import re
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class IdracRedfishUtils(RedfishUtils):
|
||||
|
||||
def create_bios_config_job(self):
|
||||
result = {}
|
||||
key = "Bios"
|
||||
jobs = "Jobs"
|
||||
|
||||
# Search for 'key' entry and extract URI from it
|
||||
response = self.get_request(self.root_uri + self.systems_uris[0])
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
result['ret'] = True
|
||||
data = response['data']
|
||||
|
||||
if key not in data:
|
||||
return {'ret': False, 'msg': "Key %s not found" % key}
|
||||
|
||||
bios_uri = data[key]["@odata.id"]
|
||||
|
||||
# Extract proper URI
|
||||
response = self.get_request(self.root_uri + bios_uri)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
result['ret'] = True
|
||||
data = response['data']
|
||||
set_bios_attr_uri = data["@Redfish.Settings"]["SettingsObject"][
|
||||
"@odata.id"]
|
||||
|
||||
payload = {"TargetSettingsURI": set_bios_attr_uri}
|
||||
response = self.post_request(
|
||||
self.root_uri + self.manager_uri + "/" + jobs, payload)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
|
||||
response_output = response['resp'].__dict__
|
||||
job_id = response_output["headers"]["Location"]
|
||||
job_id = re.search("JID_.+", job_id).group()
|
||||
# Currently not passing job_id back to user but patch is coming
|
||||
return {'ret': True, 'msg': "Config job %s created" % job_id}
|
||||
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["CreateBiosConfigJob"],
|
||||
"Accounts": [],
|
||||
"Manager": []
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
timeout=dict(type='int', default=10),
|
||||
resource_id=dict()
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# System, Manager or Chassis ID to modify
|
||||
resource_id = module.params['resource_id']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,
|
||||
resource_id=resource_id, data_modification=True)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, CATEGORY_COMMANDS_ALL.keys())))
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
|
||||
|
||||
# Organize by Categories / Commands
|
||||
|
||||
if category == "Systems":
|
||||
# execute only if we find a System resource
|
||||
result = rf_utils._find_systems_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if command == "CreateBiosConfigJob":
|
||||
# execute only if we find a Managers resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
result = rf_utils.create_bios_config_job()
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
del result['ret']
|
||||
module.exit_json(changed=True, msg='Action was successful')
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,329 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: idrac_redfish_config
|
||||
short_description: Manages servers through iDRAC using Dell Redfish APIs
|
||||
description:
|
||||
- For use with Dell iDRAC operations that require Redfish OEM extensions
|
||||
- Builds Redfish URIs locally and sends them to remote iDRAC controllers to
|
||||
set or update a configuration attribute.
|
||||
options:
|
||||
category:
|
||||
required: true
|
||||
type: str
|
||||
description:
|
||||
- Category to execute on iDRAC
|
||||
command:
|
||||
required: true
|
||||
description:
|
||||
- List of commands to execute on iDRAC
|
||||
- I(SetManagerAttributes), I(SetLifecycleControllerAttributes) and
|
||||
I(SetSystemAttributes) are mutually exclusive commands when C(category)
|
||||
is I(Manager)
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of iDRAC
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- User for authentication with iDRAC
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with iDRAC
|
||||
type: str
|
||||
manager_attribute_name:
|
||||
required: false
|
||||
description:
|
||||
- (deprecated) name of iDRAC attribute to update
|
||||
type: str
|
||||
manager_attribute_value:
|
||||
required: false
|
||||
description:
|
||||
- (deprecated) value of iDRAC attribute to update
|
||||
type: str
|
||||
manager_attributes:
|
||||
required: false
|
||||
description:
|
||||
- dictionary of iDRAC attribute name and value pairs to update
|
||||
default: {}
|
||||
type: 'dict'
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to iDRAC controller
|
||||
default: 10
|
||||
type: int
|
||||
resource_id:
|
||||
required: false
|
||||
description:
|
||||
- The ID of the System, Manager or Chassis to modify
|
||||
type: str
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Enable NTP and set NTP server and Time zone attributes in iDRAC
|
||||
idrac_redfish_config:
|
||||
category: Manager
|
||||
command: SetManagerAttributes
|
||||
resource_id: iDRAC.Embedded.1
|
||||
manager_attributes:
|
||||
NTPConfigGroup.1.NTPEnable: "Enabled"
|
||||
NTPConfigGroup.1.NTP1: "{{ ntpserver1 }}"
|
||||
Time.1.Timezone: "{{ timezone }}"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username}}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Enable Syslog and set Syslog servers in iDRAC
|
||||
idrac_redfish_config:
|
||||
category: Manager
|
||||
command: SetManagerAttributes
|
||||
resource_id: iDRAC.Embedded.1
|
||||
manager_attributes:
|
||||
SysLog.1.SysLogEnable: "Enabled"
|
||||
SysLog.1.Server1: "{{ syslog_server1 }}"
|
||||
SysLog.1.Server2: "{{ syslog_server2 }}"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username}}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Configure SNMP community string, port, protocol and trap format
|
||||
idrac_redfish_config:
|
||||
category: Manager
|
||||
command: SetManagerAttributes
|
||||
resource_id: iDRAC.Embedded.1
|
||||
manager_attributes:
|
||||
SNMP.1.AgentEnable: "Enabled"
|
||||
SNMP.1.AgentCommunity: "public_community_string"
|
||||
SNMP.1.TrapFormat: "SNMPv1"
|
||||
SNMP.1.SNMPProtocol: "All"
|
||||
SNMP.1.DiscoveryPort: 161
|
||||
SNMP.1.AlertPort: 162
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username}}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Enable CSIOR
|
||||
idrac_redfish_config:
|
||||
category: Manager
|
||||
command: SetLifecycleControllerAttributes
|
||||
resource_id: iDRAC.Embedded.1
|
||||
manager_attributes:
|
||||
LCAttributes.1.CollectSystemInventoryOnRestart: "Enabled"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username}}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set Power Supply Redundancy Policy to A/B Grid Redundant
|
||||
idrac_redfish_config:
|
||||
category: Manager
|
||||
command: SetSystemAttributes
|
||||
resource_id: iDRAC.Embedded.1
|
||||
manager_attributes:
|
||||
ServerPwr.1.PSRedPolicy: "A/B Grid Redundant"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username}}"
|
||||
password: "{{ password }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
msg:
|
||||
description: Message with action result or error description
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Action was successful"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.validation import (
|
||||
check_mutually_exclusive,
|
||||
check_required_arguments
|
||||
)
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class IdracRedfishUtils(RedfishUtils):
|
||||
|
||||
def set_manager_attributes(self, command):
|
||||
|
||||
result = {}
|
||||
required_arg_spec = {'manager_attributes': {'required': True}}
|
||||
|
||||
try:
|
||||
check_required_arguments(required_arg_spec, self.module.params)
|
||||
|
||||
except TypeError as e:
|
||||
msg = to_native(e)
|
||||
self.module.fail_json(msg=msg)
|
||||
|
||||
key = "Attributes"
|
||||
command_manager_attributes_uri_map = {
|
||||
"SetManagerAttributes": self.manager_uri,
|
||||
"SetLifecycleControllerAttributes": "/redfish/v1/Managers/LifecycleController.Embedded.1",
|
||||
"SetSystemAttributes": "/redfish/v1/Managers/System.Embedded.1"
|
||||
}
|
||||
manager_uri = command_manager_attributes_uri_map.get(command, self.manager_uri)
|
||||
|
||||
attributes = self.module.params['manager_attributes']
|
||||
manager_attr_name = self.module.params.get('manager_attribute_name')
|
||||
manager_attr_value = self.module.params.get('manager_attribute_value')
|
||||
|
||||
# manager attributes to update
|
||||
if manager_attr_name:
|
||||
attributes.update({manager_attr_name: manager_attr_value})
|
||||
|
||||
attrs_to_patch = {}
|
||||
attrs_skipped = {}
|
||||
|
||||
# Search for key entry and extract URI from it
|
||||
response = self.get_request(self.root_uri + manager_uri + "/" + key)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
result['ret'] = True
|
||||
data = response['data']
|
||||
|
||||
if key not in data:
|
||||
return {'ret': False,
|
||||
'msg': "%s: Key %s not found" % (command, key)}
|
||||
|
||||
for attr_name, attr_value in attributes.items():
|
||||
# Check if attribute exists
|
||||
if attr_name not in data[u'Attributes']:
|
||||
return {'ret': False,
|
||||
'msg': "%s: Manager attribute %s not found" % (command, attr_name)}
|
||||
|
||||
# Find out if value is already set to what we want. If yes, exclude
|
||||
# those attributes
|
||||
if data[u'Attributes'][attr_name] == attr_value:
|
||||
attrs_skipped.update({attr_name: attr_value})
|
||||
else:
|
||||
attrs_to_patch.update({attr_name: attr_value})
|
||||
|
||||
if not attrs_to_patch:
|
||||
return {'ret': True, 'changed': False,
|
||||
'msg': "Manager attributes already set"}
|
||||
|
||||
payload = {"Attributes": attrs_to_patch}
|
||||
response = self.patch_request(self.root_uri + manager_uri + "/" + key, payload)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
return {'ret': True, 'changed': True,
|
||||
'msg': "%s: Modified Manager attributes %s" % (command, attrs_to_patch)}
|
||||
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Manager": ["SetManagerAttributes", "SetLifecycleControllerAttributes",
|
||||
"SetSystemAttributes"]
|
||||
}
|
||||
|
||||
# list of mutually exclusive commands for a category
|
||||
CATEGORY_COMMANDS_MUTUALLY_EXCLUSIVE = {
|
||||
"Manager": [["SetManagerAttributes", "SetLifecycleControllerAttributes",
|
||||
"SetSystemAttributes"]]
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
manager_attribute_name=dict(default=None),
|
||||
manager_attribute_value=dict(default=None),
|
||||
manager_attributes=dict(type='dict', default={}),
|
||||
timeout=dict(type='int', default=10),
|
||||
resource_id=dict()
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# System, Manager or Chassis ID to modify
|
||||
resource_id = module.params['resource_id']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module,
|
||||
resource_id=resource_id, data_modification=True)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, CATEGORY_COMMANDS_ALL.keys())))
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
|
||||
|
||||
# check for mutually exclusive commands
|
||||
try:
|
||||
# check_mutually_exclusive accepts a single list or list of lists that
|
||||
# are groups of terms that should be mutually exclusive with one another
|
||||
# and checks that against a dictionary
|
||||
check_mutually_exclusive(CATEGORY_COMMANDS_MUTUALLY_EXCLUSIVE[category],
|
||||
dict.fromkeys(command_list, True))
|
||||
|
||||
except TypeError as e:
|
||||
module.fail_json(msg=to_native(e))
|
||||
|
||||
# Organize by Categories / Commands
|
||||
|
||||
if category == "Manager":
|
||||
# execute only if we find a Manager resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if command in ["SetManagerAttributes", "SetLifecycleControllerAttributes", "SetSystemAttributes"]:
|
||||
result = rf_utils.set_manager_attributes(command)
|
||||
|
||||
if any((module.params['manager_attribute_name'], module.params['manager_attribute_value'])):
|
||||
module.deprecate(msg='Arguments `manager_attribute_name` and '
|
||||
'`manager_attribute_value` are deprecated. '
|
||||
'Use `manager_attributes` instead for passing in '
|
||||
'the manager attribute name and value pairs',
|
||||
version='2.13')
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
plugins/modules/remote_management/redfish/idrac_redfish_facts.py
Symbolic link
1
plugins/modules/remote_management/redfish/idrac_redfish_facts.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
idrac_redfish_info.py
|
239
plugins/modules/remote_management/redfish/idrac_redfish_info.py
Normal file
239
plugins/modules/remote_management/redfish/idrac_redfish_info.py
Normal file
|
@ -0,0 +1,239 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: idrac_redfish_info
|
||||
short_description: Gather PowerEdge server information through iDRAC using Redfish APIs
|
||||
description:
|
||||
- Builds Redfish URIs locally and sends them to remote iDRAC controllers to
|
||||
get information back.
|
||||
- For use with Dell EMC iDRAC operations that require Redfish OEM extensions
|
||||
- This module was called C(idrac_redfish_facts) before Ansible 2.9, returning C(ansible_facts).
|
||||
Note that the M(idrac_redfish_info) module no longer returns C(ansible_facts)!
|
||||
options:
|
||||
category:
|
||||
required: true
|
||||
description:
|
||||
- Category to execute on iDRAC controller
|
||||
type: str
|
||||
command:
|
||||
required: true
|
||||
description:
|
||||
- List of commands to execute on iDRAC controller
|
||||
- C(GetManagerAttributes) returns the list of dicts containing iDRAC,
|
||||
LifecycleController and System attributes
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of iDRAC controller
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- User for authentication with iDRAC controller
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with iDRAC controller
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to OOB controller
|
||||
default: 10
|
||||
type: int
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get Manager attributes with a default of 20 seconds
|
||||
idrac_redfish_info:
|
||||
category: Manager
|
||||
command: GetManagerAttributes
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
timeout: 20
|
||||
register: result
|
||||
|
||||
# Examples to display the value of all or a single iDRAC attribute
|
||||
- name: Store iDRAC attributes as a fact variable
|
||||
set_fact:
|
||||
idrac_attributes: "{{ result.redfish_facts.entries | selectattr('Id', 'defined') | selectattr('Id', 'equalto', 'iDRACAttributes') | list | first }}"
|
||||
|
||||
- name: Display all iDRAC attributes
|
||||
debug:
|
||||
var: idrac_attributes
|
||||
|
||||
- name: Display the value of 'Syslog.1.SysLogEnable' iDRAC attribute
|
||||
debug:
|
||||
var: idrac_attributes['Syslog.1.SysLogEnable']
|
||||
|
||||
# Examples to display the value of all or a single LifecycleController attribute
|
||||
- name: Store LifecycleController attributes as a fact variable
|
||||
set_fact:
|
||||
lc_attributes: "{{ result.redfish_facts.entries | selectattr('Id', 'defined') | selectattr('Id', 'equalto', 'LCAttributes') | list | first }}"
|
||||
|
||||
- name: Display LifecycleController attributes
|
||||
debug:
|
||||
var: lc_attributes
|
||||
|
||||
- name: Display the value of 'CollectSystemInventoryOnRestart' attribute
|
||||
debug:
|
||||
var: lc_attributes['LCAttributes.1.CollectSystemInventoryOnRestart']
|
||||
|
||||
# Examples to display the value of all or a single System attribute
|
||||
- name: Store System attributes as a fact variable
|
||||
set_fact:
|
||||
system_attributes: "{{ result.redfish_facts.entries | selectattr('Id', 'defined') | selectattr('Id', 'equalto', 'SystemAttributes') | list | first }}"
|
||||
|
||||
- name: Display System attributes
|
||||
debug:
|
||||
var: system_attributes
|
||||
|
||||
- name: Display the value of 'PSRedPolicy'
|
||||
debug:
|
||||
var: system_attributes['ServerPwr.1.PSRedPolicy']
|
||||
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
msg:
|
||||
description: different results depending on task
|
||||
returned: always
|
||||
type: dict
|
||||
sample: List of Manager attributes
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
class IdracRedfishUtils(RedfishUtils):
|
||||
|
||||
def get_manager_attributes(self):
|
||||
result = {}
|
||||
manager_attributes = []
|
||||
properties = ['Attributes', 'Id']
|
||||
|
||||
response = self.get_request(self.root_uri + self.manager_uri)
|
||||
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
|
||||
# Manager attributes are supported as part of iDRAC OEM extension
|
||||
# Attributes are supported only on iDRAC9
|
||||
try:
|
||||
for members in data[u'Links'][u'Oem'][u'Dell'][u'DellAttributes']:
|
||||
attributes_uri = members[u'@odata.id']
|
||||
|
||||
response = self.get_request(self.root_uri + attributes_uri)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
|
||||
attributes = {}
|
||||
for prop in properties:
|
||||
if prop in data:
|
||||
attributes[prop] = data.get(prop)
|
||||
|
||||
if attributes:
|
||||
manager_attributes.append(attributes)
|
||||
|
||||
result['ret'] = True
|
||||
|
||||
except (AttributeError, KeyError) as e:
|
||||
result['ret'] = False
|
||||
result['msg'] = "Failed to find attribute/key: " + str(e)
|
||||
|
||||
result["entries"] = manager_attributes
|
||||
return result
|
||||
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Manager": ["GetManagerAttributes"]
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
timeout=dict(type='int', default=10)
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
is_old_facts = module._name == 'idrac_redfish_facts'
|
||||
if is_old_facts:
|
||||
module.deprecate("The 'idrac_redfish_facts' module has been renamed to 'idrac_redfish_info', "
|
||||
"and the renamed one no longer returns ansible_facts", version='2.13')
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, CATEGORY_COMMANDS_ALL.keys())))
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
|
||||
|
||||
# Organize by Categories / Commands
|
||||
|
||||
if category == "Manager":
|
||||
# execute only if we find a Manager resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetManagerAttributes":
|
||||
result = rf_utils.get_manager_attributes()
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
del result['ret']
|
||||
if is_old_facts:
|
||||
module.exit_json(ansible_facts=dict(redfish_facts=result))
|
||||
else:
|
||||
module.exit_json(redfish_facts=result)
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
552
plugins/modules/remote_management/redfish/redfish_command.py
Normal file
552
plugins/modules/remote_management/redfish/redfish_command.py
Normal file
|
@ -0,0 +1,552 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2017-2018 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: redfish_command
|
||||
short_description: Manages Out-Of-Band controllers using Redfish APIs
|
||||
description:
|
||||
- Builds Redfish URIs locally and sends them to remote OOB controllers to
|
||||
perform an action.
|
||||
- Manages OOB controller ex. reboot, log management.
|
||||
- Manages OOB controller users ex. add, remove, update.
|
||||
- Manages system power ex. on, off, graceful and forced reboot.
|
||||
options:
|
||||
category:
|
||||
required: true
|
||||
description:
|
||||
- Category to execute on OOB controller
|
||||
type: str
|
||||
command:
|
||||
required: true
|
||||
description:
|
||||
- List of commands to execute on OOB controller
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of OOB controller
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- Username for authentication with OOB controller
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with OOB controller
|
||||
type: str
|
||||
id:
|
||||
required: false
|
||||
aliases: [ account_id ]
|
||||
description:
|
||||
- ID of account to delete/modify
|
||||
type: str
|
||||
new_username:
|
||||
required: false
|
||||
aliases: [ account_username ]
|
||||
description:
|
||||
- Username of account to add/delete/modify
|
||||
type: str
|
||||
new_password:
|
||||
required: false
|
||||
aliases: [ account_password ]
|
||||
description:
|
||||
- New password of account to add/modify
|
||||
type: str
|
||||
roleid:
|
||||
required: false
|
||||
aliases: [ account_roleid ]
|
||||
description:
|
||||
- Role of account to add/modify
|
||||
type: str
|
||||
bootdevice:
|
||||
required: false
|
||||
description:
|
||||
- bootdevice when setting boot configuration
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to OOB controller
|
||||
default: 10
|
||||
type: int
|
||||
uefi_target:
|
||||
required: false
|
||||
description:
|
||||
- UEFI target when bootdevice is "UefiTarget"
|
||||
type: str
|
||||
boot_next:
|
||||
required: false
|
||||
description:
|
||||
- BootNext target when bootdevice is "UefiBootNext"
|
||||
type: str
|
||||
update_username:
|
||||
required: false
|
||||
aliases: [ account_updatename ]
|
||||
description:
|
||||
- new update user name for account_username
|
||||
type: str
|
||||
account_properties:
|
||||
required: false
|
||||
description:
|
||||
- properties of account service to update
|
||||
type: dict
|
||||
resource_id:
|
||||
required: false
|
||||
description:
|
||||
- The ID of the System, Manager or Chassis to modify
|
||||
type: str
|
||||
update_image_uri:
|
||||
required: false
|
||||
description:
|
||||
- The URI of the image for the update
|
||||
type: str
|
||||
update_protocol:
|
||||
required: false
|
||||
description:
|
||||
- The protocol for the update
|
||||
type: str
|
||||
update_targets:
|
||||
required: false
|
||||
description:
|
||||
- The list of target resource URIs to apply the update to
|
||||
type: list
|
||||
elements: str
|
||||
update_creds:
|
||||
required: false
|
||||
description:
|
||||
- The credentials for retrieving the update image
|
||||
type: dict
|
||||
suboptions:
|
||||
username:
|
||||
required: false
|
||||
description:
|
||||
- The username for retrieving the update image
|
||||
type: str
|
||||
password:
|
||||
required: false
|
||||
description:
|
||||
- The password for retrieving the update image
|
||||
type: str
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Restart system power gracefully
|
||||
redfish_command:
|
||||
category: Systems
|
||||
command: PowerGracefulRestart
|
||||
resource_id: 437XR1138R2
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set one-time boot device to {{ bootdevice }}
|
||||
redfish_command:
|
||||
category: Systems
|
||||
command: SetOneTimeBoot
|
||||
resource_id: 437XR1138R2
|
||||
bootdevice: "{{ bootdevice }}"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set one-time boot device to UefiTarget of "/0x31/0x33/0x01/0x01"
|
||||
redfish_command:
|
||||
category: Systems
|
||||
command: SetOneTimeBoot
|
||||
resource_id: 437XR1138R2
|
||||
bootdevice: "UefiTarget"
|
||||
uefi_target: "/0x31/0x33/0x01/0x01"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set one-time boot device to BootNext target of "Boot0001"
|
||||
redfish_command:
|
||||
category: Systems
|
||||
command: SetOneTimeBoot
|
||||
resource_id: 437XR1138R2
|
||||
bootdevice: "UefiBootNext"
|
||||
boot_next: "Boot0001"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set chassis indicator LED to blink
|
||||
redfish_command:
|
||||
category: Chassis
|
||||
command: IndicatorLedBlink
|
||||
resource_id: 1U
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Add user
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: AddUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
new_username: "{{ new_username }}"
|
||||
new_password: "{{ new_password }}"
|
||||
roleid: "{{ roleid }}"
|
||||
|
||||
- name: Add user using new option aliases
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: AddUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
account_password: "{{ account_password }}"
|
||||
account_roleid: "{{ account_roleid }}"
|
||||
|
||||
- name: Delete user
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: DeleteUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
|
||||
- name: Disable user
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: DisableUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
|
||||
- name: Enable user
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: EnableUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
|
||||
- name: Add and enable user
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: AddUser,EnableUser
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
new_username: "{{ new_username }}"
|
||||
new_password: "{{ new_password }}"
|
||||
roleid: "{{ roleid }}"
|
||||
|
||||
- name: Update user password
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: UpdateUserPassword
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
account_password: "{{ account_password }}"
|
||||
|
||||
- name: Update user role
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: UpdateUserRole
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
roleid: "{{ roleid }}"
|
||||
|
||||
- name: Update user name
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: UpdateUserName
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
account_updatename: "{{ account_updatename }}"
|
||||
|
||||
- name: Update user name
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: UpdateUserName
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_username: "{{ account_username }}"
|
||||
update_username: "{{ update_username }}"
|
||||
|
||||
- name: Update AccountService properties
|
||||
redfish_command:
|
||||
category: Accounts
|
||||
command: UpdateAccountServiceProperties
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
account_properties:
|
||||
AccountLockoutThreshold: 5
|
||||
AccountLockoutDuration: 600
|
||||
|
||||
- name: Clear Manager Logs with a timeout of 20 seconds
|
||||
redfish_command:
|
||||
category: Manager
|
||||
command: ClearLogs
|
||||
resource_id: BMC
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
timeout: 20
|
||||
|
||||
- name: Clear Sessions
|
||||
redfish_command:
|
||||
category: Sessions
|
||||
command: ClearSessions
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Simple update
|
||||
redfish_command:
|
||||
category: Update
|
||||
command: SimpleUpdate
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
update_image_uri: https://example.com/myupdate.img
|
||||
|
||||
- name: Simple update with additional options
|
||||
redfish_command:
|
||||
category: Update
|
||||
command: SimpleUpdate
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
update_image_uri: //example.com/myupdate.img
|
||||
update_protocol: FTP
|
||||
update_targets:
|
||||
- /redfish/v1/UpdateService/FirmwareInventory/BMC
|
||||
update_creds:
|
||||
username: operator
|
||||
password: supersecretpwd
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
msg:
|
||||
description: Message with action result or error description
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Action was successful"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
# More will be added as module features are expanded
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["PowerOn", "PowerForceOff", "PowerForceRestart", "PowerGracefulRestart",
|
||||
"PowerGracefulShutdown", "PowerReboot", "SetOneTimeBoot"],
|
||||
"Chassis": ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"],
|
||||
"Accounts": ["AddUser", "EnableUser", "DeleteUser", "DisableUser",
|
||||
"UpdateUserRole", "UpdateUserPassword", "UpdateUserName",
|
||||
"UpdateAccountServiceProperties"],
|
||||
"Sessions": ["ClearSessions"],
|
||||
"Manager": ["GracefulRestart", "ClearLogs"],
|
||||
"Update": ["SimpleUpdate"]
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
id=dict(aliases=["account_id"]),
|
||||
new_username=dict(aliases=["account_username"]),
|
||||
new_password=dict(aliases=["account_password"], no_log=True),
|
||||
roleid=dict(aliases=["account_roleid"]),
|
||||
update_username=dict(type='str', aliases=["account_updatename"]),
|
||||
account_properties=dict(type='dict', default={}),
|
||||
bootdevice=dict(),
|
||||
timeout=dict(type='int', default=10),
|
||||
uefi_target=dict(),
|
||||
boot_next=dict(),
|
||||
resource_id=dict(),
|
||||
update_image_uri=dict(),
|
||||
update_protocol=dict(),
|
||||
update_targets=dict(type='list', elements='str', default=[]),
|
||||
update_creds=dict(
|
||||
type='dict',
|
||||
options=dict(
|
||||
username=dict(),
|
||||
password=dict()
|
||||
)
|
||||
)
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# user to add/modify/delete
|
||||
user = {'account_id': module.params['id'],
|
||||
'account_username': module.params['new_username'],
|
||||
'account_password': module.params['new_password'],
|
||||
'account_roleid': module.params['roleid'],
|
||||
'account_updatename': module.params['update_username'],
|
||||
'account_properties': module.params['account_properties']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# System, Manager or Chassis ID to modify
|
||||
resource_id = module.params['resource_id']
|
||||
|
||||
# update options
|
||||
update_opts = {
|
||||
'update_image_uri': module.params['update_image_uri'],
|
||||
'update_protocol': module.params['update_protocol'],
|
||||
'update_targets': module.params['update_targets'],
|
||||
'update_creds': module.params['update_creds']
|
||||
}
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
||||
resource_id=resource_id, data_modification=True)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, CATEGORY_COMMANDS_ALL.keys())))
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
|
||||
|
||||
# Organize by Categories / Commands
|
||||
if category == "Accounts":
|
||||
ACCOUNTS_COMMANDS = {
|
||||
"AddUser": rf_utils.add_user,
|
||||
"EnableUser": rf_utils.enable_user,
|
||||
"DeleteUser": rf_utils.delete_user,
|
||||
"DisableUser": rf_utils.disable_user,
|
||||
"UpdateUserRole": rf_utils.update_user_role,
|
||||
"UpdateUserPassword": rf_utils.update_user_password,
|
||||
"UpdateUserName": rf_utils.update_user_name,
|
||||
"UpdateAccountServiceProperties": rf_utils.update_accountservice_properties
|
||||
}
|
||||
|
||||
# execute only if we find an Account service resource
|
||||
result = rf_utils._find_accountservice_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
result = ACCOUNTS_COMMANDS[command](user)
|
||||
|
||||
elif category == "Systems":
|
||||
# execute only if we find a System resource
|
||||
result = rf_utils._find_systems_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if "Power" in command:
|
||||
result = rf_utils.manage_system_power(command)
|
||||
elif command == "SetOneTimeBoot":
|
||||
result = rf_utils.set_one_time_boot_device(
|
||||
module.params['bootdevice'],
|
||||
module.params['uefi_target'],
|
||||
module.params['boot_next'])
|
||||
|
||||
elif category == "Chassis":
|
||||
result = rf_utils._find_chassis_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
led_commands = ["IndicatorLedOn", "IndicatorLedOff", "IndicatorLedBlink"]
|
||||
|
||||
# Check if more than one led_command is present
|
||||
num_led_commands = sum([command in led_commands for command in command_list])
|
||||
if num_led_commands > 1:
|
||||
result = {'ret': False, 'msg': "Only one IndicatorLed command should be sent at a time."}
|
||||
else:
|
||||
for command in command_list:
|
||||
if command in led_commands:
|
||||
result = rf_utils.manage_indicator_led(command)
|
||||
|
||||
elif category == "Sessions":
|
||||
# execute only if we find SessionService resources
|
||||
resource = rf_utils._find_sessionservice_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "ClearSessions":
|
||||
result = rf_utils.clear_sessions()
|
||||
|
||||
elif category == "Manager":
|
||||
MANAGER_COMMANDS = {
|
||||
"GracefulRestart": rf_utils.restart_manager_gracefully,
|
||||
"ClearLogs": rf_utils.clear_logs
|
||||
}
|
||||
|
||||
# execute only if we find a Manager service resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
result = MANAGER_COMMANDS[command]()
|
||||
|
||||
elif category == "Update":
|
||||
# execute only if we find UpdateService resources
|
||||
resource = rf_utils._find_updateservice_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "SimpleUpdate":
|
||||
result = rf_utils.simple_update(update_opts)
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
del result['ret']
|
||||
changed = result.get('changed', True)
|
||||
module.exit_json(changed=changed, msg='Action was successful')
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
332
plugins/modules/remote_management/redfish/redfish_config.py
Normal file
332
plugins/modules/remote_management/redfish/redfish_config.py
Normal file
|
@ -0,0 +1,332 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2017-2018 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: redfish_config
|
||||
short_description: Manages Out-Of-Band controllers using Redfish APIs
|
||||
description:
|
||||
- Builds Redfish URIs locally and sends them to remote OOB controllers to
|
||||
set or update a configuration attribute.
|
||||
- Manages BIOS configuration settings.
|
||||
- Manages OOB controller configuration settings.
|
||||
options:
|
||||
category:
|
||||
required: true
|
||||
description:
|
||||
- Category to execute on OOB controller
|
||||
type: str
|
||||
command:
|
||||
required: true
|
||||
description:
|
||||
- List of commands to execute on OOB controller
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of OOB controller
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- User for authentication with OOB controller
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with OOB controller
|
||||
type: str
|
||||
bios_attribute_name:
|
||||
required: false
|
||||
description:
|
||||
- name of BIOS attr to update (deprecated - use bios_attributes instead)
|
||||
default: 'null'
|
||||
type: str
|
||||
bios_attribute_value:
|
||||
required: false
|
||||
description:
|
||||
- value of BIOS attr to update (deprecated - use bios_attributes instead)
|
||||
default: 'null'
|
||||
type: str
|
||||
bios_attributes:
|
||||
required: false
|
||||
description:
|
||||
- dictionary of BIOS attributes to update
|
||||
default: {}
|
||||
type: dict
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to OOB controller
|
||||
default: 10
|
||||
type: int
|
||||
boot_order:
|
||||
required: false
|
||||
description:
|
||||
- list of BootOptionReference strings specifying the BootOrder
|
||||
default: []
|
||||
type: list
|
||||
network_protocols:
|
||||
required: false
|
||||
description:
|
||||
- setting dict of manager services to update
|
||||
type: dict
|
||||
resource_id:
|
||||
required: false
|
||||
description:
|
||||
- The ID of the System, Manager or Chassis to modify
|
||||
type: str
|
||||
nic_addr:
|
||||
required: false
|
||||
description:
|
||||
- EthernetInterface Address string on OOB controller
|
||||
default: 'null'
|
||||
type: str
|
||||
nic_config:
|
||||
required: false
|
||||
description:
|
||||
- setting dict of EthernetInterface on OOB controller
|
||||
type: dict
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Set BootMode to UEFI
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetBiosAttributes
|
||||
resource_id: 437XR1138R2
|
||||
bios_attributes:
|
||||
BootMode: "Uefi"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set multiple BootMode attributes
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetBiosAttributes
|
||||
resource_id: 437XR1138R2
|
||||
bios_attributes:
|
||||
BootMode: "Bios"
|
||||
OneTimeBootMode: "Enabled"
|
||||
BootSeqRetry: "Enabled"
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Enable PXE Boot for NIC1 using deprecated options
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetBiosAttributes
|
||||
resource_id: 437XR1138R2
|
||||
bios_attribute_name: PxeDev1EnDis
|
||||
bios_attribute_value: Enabled
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set BIOS default settings with a timeout of 20 seconds
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetBiosDefaultSettings
|
||||
resource_id: 437XR1138R2
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
timeout: 20
|
||||
|
||||
- name: Set boot order
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetBootOrder
|
||||
boot_order:
|
||||
- Boot0002
|
||||
- Boot0001
|
||||
- Boot0000
|
||||
- Boot0003
|
||||
- Boot0004
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set boot order to the default
|
||||
redfish_config:
|
||||
category: Systems
|
||||
command: SetDefaultBootOrder
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set Manager Network Protocols
|
||||
redfish_config:
|
||||
category: Manager
|
||||
command: SetNetworkProtocols
|
||||
network_protocols:
|
||||
SNMP:
|
||||
ProtocolEnabled: True
|
||||
Port: 161
|
||||
HTTP:
|
||||
ProtocolEnabled: False
|
||||
Port: 8080
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Set Manager NIC
|
||||
redfish_config:
|
||||
category: Manager
|
||||
command: SetManagerNic
|
||||
nic_config:
|
||||
DHCPv4:
|
||||
DHCPEnabled: False
|
||||
IPv4StaticAddresses:
|
||||
Address: 192.168.1.3
|
||||
Gateway: 192.168.1.1
|
||||
SubnetMask: 255.255.255.0
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
msg:
|
||||
description: Message with action result or error description
|
||||
returned: always
|
||||
type: str
|
||||
sample: "Action was successful"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
# More will be added as module features are expanded
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
||||
"SetDefaultBootOrder"],
|
||||
"Manager": ["SetNetworkProtocols", "SetManagerNic"]
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(required=True),
|
||||
command=dict(required=True, type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
bios_attribute_name=dict(default='null'),
|
||||
bios_attribute_value=dict(default='null'),
|
||||
bios_attributes=dict(type='dict', default={}),
|
||||
timeout=dict(type='int', default=10),
|
||||
boot_order=dict(type='list', elements='str', default=[]),
|
||||
network_protocols=dict(
|
||||
type='dict',
|
||||
default={}
|
||||
),
|
||||
resource_id=dict(),
|
||||
nic_addr=dict(default='null'),
|
||||
nic_config=dict(
|
||||
type='dict',
|
||||
default={}
|
||||
)
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
|
||||
category = module.params['category']
|
||||
command_list = module.params['command']
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# BIOS attributes to update
|
||||
bios_attributes = module.params['bios_attributes']
|
||||
if module.params['bios_attribute_name'] != 'null':
|
||||
bios_attributes[module.params['bios_attribute_name']] = module.params[
|
||||
'bios_attribute_value']
|
||||
module.deprecate(msg='The bios_attribute_name/bios_attribute_value '
|
||||
'options are deprecated. Use bios_attributes instead',
|
||||
version='2.14')
|
||||
|
||||
# boot order
|
||||
boot_order = module.params['boot_order']
|
||||
|
||||
# System, Manager or Chassis ID to modify
|
||||
resource_id = module.params['resource_id']
|
||||
|
||||
# manager nic
|
||||
nic_addr = module.params['nic_addr']
|
||||
nic_config = module.params['nic_config']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
||||
resource_id=resource_id, data_modification=True)
|
||||
|
||||
# Check that Category is valid
|
||||
if category not in CATEGORY_COMMANDS_ALL:
|
||||
module.fail_json(msg=to_native("Invalid Category '%s'. Valid Categories = %s" % (category, CATEGORY_COMMANDS_ALL.keys())))
|
||||
|
||||
# Check that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg=to_native("Invalid Command '%s'. Valid Commands = %s" % (cmd, CATEGORY_COMMANDS_ALL[category])))
|
||||
|
||||
# Organize by Categories / Commands
|
||||
if category == "Systems":
|
||||
# execute only if we find a System resource
|
||||
result = rf_utils._find_systems_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if command == "SetBiosDefaultSettings":
|
||||
result = rf_utils.set_bios_default_settings()
|
||||
elif command == "SetBiosAttributes":
|
||||
result = rf_utils.set_bios_attributes(bios_attributes)
|
||||
elif command == "SetBootOrder":
|
||||
result = rf_utils.set_boot_order(boot_order)
|
||||
elif command == "SetDefaultBootOrder":
|
||||
result = rf_utils.set_default_boot_order()
|
||||
|
||||
elif category == "Manager":
|
||||
# execute only if we find a Manager service resource
|
||||
result = rf_utils._find_managers_resource()
|
||||
if result['ret'] is False:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
for command in command_list:
|
||||
if command == "SetNetworkProtocols":
|
||||
result = rf_utils.set_network_protocols(module.params['network_protocols'])
|
||||
elif command == "SetManagerNic":
|
||||
result = rf_utils.set_manager_nic(nic_addr, nic_config)
|
||||
|
||||
# Return data back or fail with proper message
|
||||
if result['ret'] is True:
|
||||
module.exit_json(changed=result['changed'], msg=to_native(result['msg']))
|
||||
else:
|
||||
module.fail_json(msg=to_native(result['msg']))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
plugins/modules/remote_management/redfish/redfish_facts.py
Symbolic link
1
plugins/modules/remote_management/redfish/redfish_facts.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
redfish_info.py
|
469
plugins/modules/remote_management/redfish/redfish_info.py
Normal file
469
plugins/modules/remote_management/redfish/redfish_info.py
Normal file
|
@ -0,0 +1,469 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2017-2018 Dell EMC Inc.
|
||||
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
ANSIBLE_METADATA = {'status': ['preview'],
|
||||
'supported_by': 'community',
|
||||
'metadata_version': '1.1'}
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: redfish_info
|
||||
short_description: Manages Out-Of-Band controllers using Redfish APIs
|
||||
description:
|
||||
- Builds Redfish URIs locally and sends them to remote OOB controllers to
|
||||
get information back.
|
||||
- Information retrieved is placed in a location specified by the user.
|
||||
- This module was called C(redfish_facts) before Ansible 2.9, returning C(ansible_facts).
|
||||
Note that the M(redfish_info) module no longer returns C(ansible_facts)!
|
||||
options:
|
||||
category:
|
||||
required: false
|
||||
description:
|
||||
- List of categories to execute on OOB controller
|
||||
default: ['Systems']
|
||||
type: list
|
||||
command:
|
||||
required: false
|
||||
description:
|
||||
- List of commands to execute on OOB controller
|
||||
type: list
|
||||
baseuri:
|
||||
required: true
|
||||
description:
|
||||
- Base URI of OOB controller
|
||||
type: str
|
||||
username:
|
||||
required: true
|
||||
description:
|
||||
- User for authentication with OOB controller
|
||||
type: str
|
||||
password:
|
||||
required: true
|
||||
description:
|
||||
- Password for authentication with OOB controller
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- Timeout in seconds for URL requests to OOB controller
|
||||
default: 10
|
||||
type: int
|
||||
|
||||
author: "Jose Delarosa (@jose-delarosa)"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get CPU inventory
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetCpuInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts.cpu.entries | to_nice_json }}"
|
||||
|
||||
- name: Get CPU model
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetCpuInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts.cpu.entries.0.Model }}"
|
||||
|
||||
- name: Get memory inventory
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetMemoryInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
|
||||
- name: Get fan inventory with a timeout of 20 seconds
|
||||
redfish_info:
|
||||
category: Chassis
|
||||
command: GetFanInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
timeout: 20
|
||||
register: result
|
||||
|
||||
- name: Get Virtual Media information
|
||||
redfish_info:
|
||||
category: Manager
|
||||
command: GetVirtualMedia
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts.virtual_media.entries | to_nice_json }}"
|
||||
|
||||
- name: Get Volume Inventory
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetVolumeInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts.volume.entries | to_nice_json }}"
|
||||
|
||||
- name: Get Session information
|
||||
redfish_info:
|
||||
category: Sessions
|
||||
command: GetSessions
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts.session.entries | to_nice_json }}"
|
||||
|
||||
- name: Get default inventory information
|
||||
redfish_info:
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
register: result
|
||||
- debug:
|
||||
msg: "{{ result.redfish_facts | to_nice_json }}"
|
||||
|
||||
- name: Get several inventories
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetNicInventory,GetBiosAttributes
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get default system inventory and user information
|
||||
redfish_info:
|
||||
category: Systems,Accounts
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get default system, user and firmware information
|
||||
redfish_info:
|
||||
category: ["Systems", "Accounts", "Update"]
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get Manager NIC inventory information
|
||||
redfish_info:
|
||||
category: Manager
|
||||
command: GetManagerNicInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get boot override information
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetBootOverride
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get chassis inventory
|
||||
redfish_info:
|
||||
category: Chassis
|
||||
command: GetChassisInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get all information available in the Manager category
|
||||
redfish_info:
|
||||
category: Manager
|
||||
command: all
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get firmware update capability information
|
||||
redfish_info:
|
||||
category: Update
|
||||
command: GetFirmwareUpdateCapabilities
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get firmware inventory
|
||||
redfish_info:
|
||||
category: Update
|
||||
command: GetFirmwareInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get software inventory
|
||||
redfish_info:
|
||||
category: Update
|
||||
command: GetSoftwareInventory
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get Manager Services
|
||||
redfish_info:
|
||||
category: Manager
|
||||
command: GetNetworkProtocols
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get all information available in all categories
|
||||
redfish_info:
|
||||
category: all
|
||||
command: all
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get system health report
|
||||
redfish_info:
|
||||
category: Systems
|
||||
command: GetHealthReport
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get chassis health report
|
||||
redfish_info:
|
||||
category: Chassis
|
||||
command: GetHealthReport
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Get manager health report
|
||||
redfish_info:
|
||||
category: Manager
|
||||
command: GetHealthReport
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
result:
|
||||
description: different results depending on task
|
||||
returned: always
|
||||
type: dict
|
||||
sample: List of CPUs on system
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.general.plugins.module_utils.redfish_utils import RedfishUtils
|
||||
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
|
||||
"GetMemoryInventory", "GetNicInventory", "GetHealthReport",
|
||||
"GetStorageControllerInventory", "GetDiskInventory", "GetVolumeInventory",
|
||||
"GetBiosAttributes", "GetBootOrder", "GetBootOverride"],
|
||||
"Chassis": ["GetFanInventory", "GetPsuInventory", "GetChassisPower",
|
||||
"GetChassisThermals", "GetChassisInventory", "GetHealthReport"],
|
||||
"Accounts": ["ListUsers"],
|
||||
"Sessions": ["GetSessions"],
|
||||
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory"],
|
||||
"Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols",
|
||||
"GetHealthReport"],
|
||||
}
|
||||
|
||||
CATEGORY_COMMANDS_DEFAULT = {
|
||||
"Systems": "GetSystemInventory",
|
||||
"Chassis": "GetFanInventory",
|
||||
"Accounts": "ListUsers",
|
||||
"Update": "GetFirmwareInventory",
|
||||
"Sessions": "GetSessions",
|
||||
"Manager": "GetManagerNicInventory"
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
result = {}
|
||||
category_list = []
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
category=dict(type='list', default=['Systems']),
|
||||
command=dict(type='list'),
|
||||
baseuri=dict(required=True),
|
||||
username=dict(required=True),
|
||||
password=dict(required=True, no_log=True),
|
||||
timeout=dict(type='int', default=10)
|
||||
),
|
||||
supports_check_mode=False
|
||||
)
|
||||
is_old_facts = module._name == 'redfish_facts'
|
||||
if is_old_facts:
|
||||
module.deprecate("The 'redfish_facts' module has been renamed to 'redfish_info', "
|
||||
"and the renamed one no longer returns ansible_facts", version='2.13')
|
||||
|
||||
# admin credentials used for authentication
|
||||
creds = {'user': module.params['username'],
|
||||
'pswd': module.params['password']}
|
||||
|
||||
# timeout
|
||||
timeout = module.params['timeout']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module)
|
||||
|
||||
# Build Category list
|
||||
if "all" in module.params['category']:
|
||||
for entry in CATEGORY_COMMANDS_ALL:
|
||||
category_list.append(entry)
|
||||
else:
|
||||
# one or more categories specified
|
||||
category_list = module.params['category']
|
||||
|
||||
for category in category_list:
|
||||
command_list = []
|
||||
# Build Command list for each Category
|
||||
if category in CATEGORY_COMMANDS_ALL:
|
||||
if not module.params['command']:
|
||||
# True if we don't specify a command --> use default
|
||||
command_list.append(CATEGORY_COMMANDS_DEFAULT[category])
|
||||
elif "all" in module.params['command']:
|
||||
for entry in range(len(CATEGORY_COMMANDS_ALL[category])):
|
||||
command_list.append(CATEGORY_COMMANDS_ALL[category][entry])
|
||||
# one or more commands
|
||||
else:
|
||||
command_list = module.params['command']
|
||||
# Verify that all commands are valid
|
||||
for cmd in command_list:
|
||||
# Fail if even one command given is invalid
|
||||
if cmd not in CATEGORY_COMMANDS_ALL[category]:
|
||||
module.fail_json(msg="Invalid Command: %s" % cmd)
|
||||
else:
|
||||
# Fail if even one category given is invalid
|
||||
module.fail_json(msg="Invalid Category: %s" % category)
|
||||
|
||||
# Organize by Categories / Commands
|
||||
if category == "Systems":
|
||||
# execute only if we find a Systems resource
|
||||
resource = rf_utils._find_systems_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetSystemInventory":
|
||||
result["system"] = rf_utils.get_multi_system_inventory()
|
||||
elif command == "GetCpuInventory":
|
||||
result["cpu"] = rf_utils.get_multi_cpu_inventory()
|
||||
elif command == "GetMemoryInventory":
|
||||
result["memory"] = rf_utils.get_multi_memory_inventory()
|
||||
elif command == "GetNicInventory":
|
||||
result["nic"] = rf_utils.get_multi_nic_inventory(category)
|
||||
elif command == "GetStorageControllerInventory":
|
||||
result["storage_controller"] = rf_utils.get_multi_storage_controller_inventory()
|
||||
elif command == "GetDiskInventory":
|
||||
result["disk"] = rf_utils.get_multi_disk_inventory()
|
||||
elif command == "GetVolumeInventory":
|
||||
result["volume"] = rf_utils.get_multi_volume_inventory()
|
||||
elif command == "GetBiosAttributes":
|
||||
result["bios_attribute"] = rf_utils.get_multi_bios_attributes()
|
||||
elif command == "GetBootOrder":
|
||||
result["boot_order"] = rf_utils.get_multi_boot_order()
|
||||
elif command == "GetBootOverride":
|
||||
result["boot_override"] = rf_utils.get_multi_boot_override()
|
||||
elif command == "GetHealthReport":
|
||||
result["health_report"] = rf_utils.get_multi_system_health_report()
|
||||
|
||||
elif category == "Chassis":
|
||||
# execute only if we find Chassis resource
|
||||
resource = rf_utils._find_chassis_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetFanInventory":
|
||||
result["fan"] = rf_utils.get_fan_inventory()
|
||||
elif command == "GetPsuInventory":
|
||||
result["psu"] = rf_utils.get_psu_inventory()
|
||||
elif command == "GetChassisThermals":
|
||||
result["thermals"] = rf_utils.get_chassis_thermals()
|
||||
elif command == "GetChassisPower":
|
||||
result["chassis_power"] = rf_utils.get_chassis_power()
|
||||
elif command == "GetChassisInventory":
|
||||
result["chassis"] = rf_utils.get_chassis_inventory()
|
||||
elif command == "GetHealthReport":
|
||||
result["health_report"] = rf_utils.get_multi_chassis_health_report()
|
||||
|
||||
elif category == "Accounts":
|
||||
# execute only if we find an Account service resource
|
||||
resource = rf_utils._find_accountservice_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "ListUsers":
|
||||
result["user"] = rf_utils.list_users()
|
||||
|
||||
elif category == "Update":
|
||||
# execute only if we find UpdateService resources
|
||||
resource = rf_utils._find_updateservice_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetFirmwareInventory":
|
||||
result["firmware"] = rf_utils.get_firmware_inventory()
|
||||
elif command == "GetSoftwareInventory":
|
||||
result["software"] = rf_utils.get_software_inventory()
|
||||
elif command == "GetFirmwareUpdateCapabilities":
|
||||
result["firmware_update_capabilities"] = rf_utils.get_firmware_update_capabilities()
|
||||
|
||||
elif category == "Sessions":
|
||||
# execute only if we find SessionService resources
|
||||
resource = rf_utils._find_sessionservice_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetSessions":
|
||||
result["session"] = rf_utils.get_sessions()
|
||||
|
||||
elif category == "Manager":
|
||||
# execute only if we find a Manager service resource
|
||||
resource = rf_utils._find_managers_resource()
|
||||
if resource['ret'] is False:
|
||||
module.fail_json(msg=resource['msg'])
|
||||
|
||||
for command in command_list:
|
||||
if command == "GetManagerNicInventory":
|
||||
result["manager_nics"] = rf_utils.get_multi_nic_inventory(category)
|
||||
elif command == "GetVirtualMedia":
|
||||
result["virtual_media"] = rf_utils.get_multi_virtualmedia()
|
||||
elif command == "GetLogs":
|
||||
result["log"] = rf_utils.get_logs()
|
||||
elif command == "GetNetworkProtocols":
|
||||
result["network_protocols"] = rf_utils.get_network_protocols()
|
||||
elif command == "GetHealthReport":
|
||||
result["health_report"] = rf_utils.get_multi_manager_health_report()
|
||||
|
||||
# Return data back
|
||||
if is_old_facts:
|
||||
module.exit_json(ansible_facts=dict(redfish_facts=result))
|
||||
else:
|
||||
module.exit_json(redfish_facts=result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue