| 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_iscsi_boot_policy_info |
| 16 |
short_description: Gather information about iSCSI Boot Policies in Cisco Intersight |
| 17 |
description: |
| 18 |
- Retrieve information about iSCSI Boot Policies from L(Cisco Intersight,https://intersight.com). |
| 19 |
- Query policies by organization or policy name. |
| 20 |
- Returns structured data with policy metadata and iSCSI boot configuration details. |
| 21 |
- If no filters are provided, all iSCSI Boot Policies will be returned. |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
organization: |
| 25 |
description: |
| 26 |
- The name of the organization to filter iSCSI Boot Policies by. |
| 27 |
- Use 'default' for the default organization. |
| 28 |
- When specified, only policies from this organization will be returned. |
| 29 |
type: str |
| 30 |
name: |
| 31 |
description: |
| 32 |
- The exact name of the iSCSI Boot Policy to retrieve information from. |
| 33 |
- When specified, only the matching policy will be returned. |
| 34 |
type: str |
| 35 |
author: |
| 36 |
- Ron Gershburg (@rgershbu) |
| 37 |
''' |
| 38 |
|
| 39 |
EXAMPLES = r''' |
| 40 |
# Basic Usage Examples |
| 41 |
- name: Fetch all iSCSI Boot Policies from all organizations |
| 42 |
cisco.intersight.intersight_iscsi_boot_policy_info: |
| 43 |
api_private_key: "{{ api_private_key }}" |
| 44 |
api_key_id: "{{ api_key_id }}" |
| 45 |
register: all_iscsi_boot_policies |
| 46 |
|
| 47 |
# Organization-specific Examples |
| 48 |
- name: Fetch all iSCSI Boot Policies from the default organization |
| 49 |
cisco.intersight.intersight_iscsi_boot_policy_info: |
| 50 |
api_private_key: "{{ api_private_key }}" |
| 51 |
api_key_id: "{{ api_key_id }}" |
| 52 |
organization: "default" |
| 53 |
register: default_org_policies |
| 54 |
|
| 55 |
- name: Fetch all iSCSI Boot Policies from a custom organization |
| 56 |
cisco.intersight.intersight_iscsi_boot_policy_info: |
| 57 |
api_private_key: "{{ api_private_key }}" |
| 58 |
api_key_id: "{{ api_key_id }}" |
| 59 |
organization: "Engineering" |
| 60 |
register: engineering_policies |
| 61 |
|
| 62 |
# Specific Policy Examples |
| 63 |
- name: Fetch a specific iSCSI Boot Policy by name |
| 64 |
cisco.intersight.intersight_iscsi_boot_policy_info: |
| 65 |
api_private_key: "{{ api_private_key }}" |
| 66 |
api_key_id: "{{ api_key_id }}" |
| 67 |
name: "iscsi-boot-policy-01" |
| 68 |
register: specific_policy |
| 69 |
|
| 70 |
- name: Fetch a specific policy from a specific organization |
| 71 |
cisco.intersight.intersight_iscsi_boot_policy_info: |
| 72 |
api_private_key: "{{ api_private_key }}" |
| 73 |
api_key_id: "{{ api_key_id }}" |
| 74 |
organization: "Production" |
| 75 |
name: "iscsi-boot-policy-prod" |
| 76 |
register: specific_org_policy |
| 77 |
''' |
| 78 |
|
| 79 |
RETURN = r''' |
| 80 |
api_response: |
| 81 |
description: |
| 82 |
- The API response containing iSCSI Boot Policy information. |
| 83 |
- Returns a list. |
| 84 |
returned: always |
| 85 |
type: dict |
| 86 |
sample: |
| 87 |
Name: "iscsi-boot-policy-01" |
| 88 |
ObjectType: "vnic.IscsiBootPolicy" |
| 89 |
Moid: "1234567890abcdef12345678" |
| 90 |
Description: "iSCSI boot policy for production servers" |
| 91 |
IscsiIpType: "IPv4" |
| 92 |
TargetSourceType: "Static" |
| 93 |
AutoTargetvendorName: "" |
| 94 |
InitiatorIpSource: "DHCP" |
| 95 |
PrimaryTargetPolicy: |
| 96 |
Moid: "abcdef1234567890abcdef12" |
| 97 |
ObjectType: "vnic.IscsiStaticTargetPolicy" |
| 98 |
SecondaryTargetPolicy: |
| 99 |
Moid: "" |
| 100 |
ObjectType: "" |
| 101 |
IscsiAdapterPolicy: |
| 102 |
Moid: "fedcba0987654321fedcba09" |
| 103 |
ObjectType: "vnic.IscsiAdapterPolicy" |
| 104 |
Chap: |
| 105 |
UserId: "chapuser" |
| 106 |
IsPasswordSet: true |
| 107 |
MutualChap: |
| 108 |
UserId: "" |
| 109 |
IsPasswordSet: false |
| 110 |
Organization: |
| 111 |
Name: "default" |
| 112 |
ObjectType: "organization.Organization" |
| 113 |
Moid: "abcdef1234567890abcdef12" |
| 114 |
Tags: |
| 115 |
- Key: "Environment" |
| 116 |
Value: "Production" |
| 117 |
- Key: "Owner" |
| 118 |
Value: "Storage-Team" |
| 119 |
''' |
| 120 |
|
| 121 |
|
| 122 |
from ansible.module_utils.basic import AnsibleModule |
| 123 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 124 |
|
| 125 |
|
| 126 |
def main(): |
| 127 |
argument_spec = intersight_argument_spec.copy() |
| 128 |
argument_spec.update( |
| 129 |
organization=dict(type='str'), |
| 130 |
name=dict(type='str') |
| 131 |
) |
| 132 |
module = AnsibleModule( |
| 133 |
argument_spec, |
| 134 |
supports_check_mode=True, |
| 135 |
) |
| 136 |
|
| 137 |
intersight = IntersightModule(module) |
| 138 |
intersight.result['api_response'] = {} |
| 139 |
intersight.result['trace_id'] = '' |
| 140 |
|
| 141 |
# Resource path used to fetch policy info |
| 142 |
resource_path = '/vnic/IscsiBootPolicies' |
| 143 |
|
| 144 |
# Get query parameters for policies |
| 145 |
query_params = intersight.set_query_params() |
| 146 |
|
| 147 |
# Get iSCSI Boot policies |
| 148 |
intersight.get_resource( |
| 149 |
resource_path=resource_path, |
| 150 |
query_params=query_params, |
| 151 |
return_list=True |
| 152 |
) |
| 153 |
|
| 154 |
module.exit_json(**intersight.result) |
| 155 |
|
| 156 |
|
| 157 |
if __name__ == '__main__': |
| 158 |
main() |