Debian Codegraph @

ansible_collections/community/general/plugins/modules/manageiq_policies_info.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2022, Alexei Znamensky <[email protected]>
3 # Copyright (c) 2017, Daniel Korn <[email protected]>
4 # Copyright (c) 2017, Yaacov Zamir <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
6 # SPDX-License-Identifier: GPL-3.0-or-later
7
8 from __future__ import annotations
9
10 DOCUMENTATION = r"""
11 module: manageiq_policies_info
12 version_added: 5.8.0
13
14 short_description: Listing of resource policy_profiles in ManageIQ
15 extends_documentation_fragment:
16 - community.general._manageiq
17 - community.general._attributes
18 - community.general._attributes.info_module
19
20 author: Alexei Znamensky (@russoz)
21 description:
22 - The manageiq_policies module supports listing policy_profiles in ManageIQ.
23 options:
24 resource_type:
25 type: str
26 description:
27 - The type of the resource to obtain the profile for.
28 required: true
29 choices:
30 - provider
31 - host
32 - vm
33 - blueprint
34 - category
35 - cluster
36 - data store
37 - group
38 - resource pool
39 - service
40 - service template
41 - template
42 - tenant
43 - user
44 resource_name:
45 type: str
46 description:
47 - The name of the resource to obtain the profile for.
48 - Must be specified if O(resource_id) is not set. Both options are mutually exclusive.
49 resource_id:
50 type: int
51 description:
52 - The ID of the resource to obtain the profile for.
53 - Must be specified if O(resource_name) is not set. Both options are mutually exclusive.
54 """
55
56 EXAMPLES = r"""
57 - name: List current policy_profile and policies for a provider in ManageIQ
58 community.general.manageiq_policies_info:
59 resource_name: 'EngLab'
60 resource_type: 'provider'
61 manageiq_connection:
62 url: 'http://127.0.0.1:3000'
63 username: 'admin'
64 password: 'smartvm'
65 register: result
66 """
67
68 RETURN = r"""
69 profiles:
70 description:
71 - List current policy_profile and policies for a provider in ManageIQ.
72 returned: always
73 type: list
74 elements: dict
75 sample:
76 - policies:
77 - active: true
78 description: OpenSCAP
79 name: openscap policy
80 - active: true,
81 description: Analyse incoming container images
82 name: analyse incoming container images
83 - active: true
84 description: Schedule compliance after smart state analysis
85 name: schedule compliance after smart state analysis
86 profile_description: OpenSCAP profile
87 profile_name: openscap profile
88 """
89
90 from ansible.module_utils.basic import AnsibleModule
91
92 from ansible_collections.community.general.plugins.module_utils._manageiq import (
93 ManageIQ,
94 manageiq_argument_spec,
95 manageiq_entities,
96 )
97
98
99 def main():
100 argument_spec = dict(
101 resource_id=dict(type="int"),
102 resource_name=dict(type="str"),
103 resource_type=dict(required=True, type="str", choices=list(manageiq_entities().keys())),
104 )
105 # add the manageiq connection arguments to the arguments
106 argument_spec.update(manageiq_argument_spec())
107
108 module = AnsibleModule(
109 argument_spec=argument_spec,
110 mutually_exclusive=[["resource_id", "resource_name"]],
111 required_one_of=[["resource_id", "resource_name"]],
112 supports_check_mode=True,
113 )
114
115 resource_id = module.params["resource_id"]
116 resource_type_key = module.params["resource_type"]
117 resource_name = module.params["resource_name"]
118
119 # get the resource type
120 resource_type = manageiq_entities()[resource_type_key]
121
122 manageiq_policies = ManageIQ(module).policies(resource_id, resource_type, resource_name)
123
124 # return a list of current profiles for this object
125 current_profiles = manageiq_policies.query_resource_profiles()
126 res_args = dict(changed=False, profiles=current_profiles)
127
128 module.exit_json(**res_args)
129
130
131 if __name__ == "__main__":
132 main()