Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_device_connector_policy.py

raw
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_device_connector_policy
16 short_description: Device Connector Policy configuration for Cisco Intersight
17 description:
18 - Manages Device Connector Policy configuration on Cisco Intersight.
19 - A policy to configure device connector settings for Cisco Intersight managed devices.
20 - Enables or disables configuration lockout on the endpoint to prevent local configuration changes.
21 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
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 and Policies 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 Device Connector 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 Device Connector 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 default: []
55 enable_lockout:
56 description:
57 - Enables configuration lockout on the endpoint.
58 - When enabled, prevents local configuration changes on the device through IMC or CIMC interfaces.
59 - Lockout ensures that all configuration changes must be made through Intersight.
60 type: bool
61 default: false
62 author:
63 - Ron Gershburg (@rgershbu)
64 '''
65
66 EXAMPLES = r'''
67 - name: Create Device Connector Policy with lockout enabled
68 cisco.intersight.intersight_device_connector_policy:
69 api_private_key: "{{ api_private_key }}"
70 api_key_id: "{{ api_key_id }}"
71 organization: "default"
72 name: "device-connector-lockout-policy"
73 description: "Device connector policy with lockout enabled"
74 enable_lockout: true
75 tags:
76 - Key: "Environment"
77 Value: "Production"
78 state: present
79
80 - name: Create Device Connector Policy with lockout disabled
81 cisco.intersight.intersight_device_connector_policy:
82 api_private_key: "{{ api_private_key }}"
83 api_key_id: "{{ api_key_id }}"
84 organization: "default"
85 name: "device-connector-no-lockout-policy"
86 description: "Device connector policy with lockout disabled"
87 enable_lockout: false
88 state: present
89
90 - name: Update existing Device Connector Policy
91 cisco.intersight.intersight_device_connector_policy:
92 api_private_key: "{{ api_private_key }}"
93 api_key_id: "{{ api_key_id }}"
94 organization: "default"
95 name: "device-connector-lockout-policy"
96 description: "Updated device connector policy"
97 enable_lockout: false
98 state: present
99
100 - name: Delete Device Connector Policy
101 cisco.intersight.intersight_device_connector_policy:
102 api_private_key: "{{ api_private_key }}"
103 api_key_id: "{{ api_key_id }}"
104 organization: "default"
105 name: "device-connector-lockout-policy"
106 state: absent
107 '''
108
109 RETURN = r'''
110 api_response:
111 description: The API response output returned by the specified resource.
112 returned: always
113 type: dict
114 sample:
115 "api_response": {
116 "Name": "device-connector-lockout-policy",
117 "ObjectType": "deviceconnector.Policy",
118 "Description": "Device connector policy with lockout enabled",
119 "LockoutEnabled": true,
120 "Organization": {
121 "Moid": "675450ee69726530014753e2",
122 "ObjectType": "organization.Organization"
123 },
124 "Tags": [
125 {
126 "Key": "Environment",
127 "Value": "Production"
128 }
129 ]
130 }
131 '''
132
133 from ansible.module_utils.basic import AnsibleModule
134 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
135
136
137 def main():
138 argument_spec = intersight_argument_spec.copy()
139 argument_spec.update(
140 state=dict(type='str', choices=['present', 'absent'], default='present'),
141 organization=dict(type='str', default='default'),
142 name=dict(type='str', required=True),
143 description=dict(type='str', aliases=['descr']),
144 tags=dict(type='list', elements='dict', default=[]),
145 enable_lockout=dict(type='bool', default=False)
146 )
147
148 module = AnsibleModule(
149 argument_spec,
150 supports_check_mode=True,
151 )
152
153 intersight = IntersightModule(module)
154 intersight.result['api_response'] = {}
155 intersight.result['trace_id'] = ''
156
157 intersight.api_body = {
158 'Organization': {
159 'Name': module.params['organization'],
160 },
161 'Name': module.params['name']
162 }
163 if module.params['state'] == 'present':
164 intersight.set_tags_and_description()
165 intersight.api_body['LockoutEnabled'] = module.params['enable_lockout']
166
167 resource_path = '/deviceconnector/Policies'
168 intersight.configure_policy_or_profile(resource_path=resource_path)
169 module.exit_json(**intersight.result)
170
171
172 if __name__ == '__main__':
173 main()