1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/modules/remote_management/manageiq/manageiq_policies_info.py

120 lines
3.8 KiB
Python
Raw Normal View History

manageiq_policies_info: new module (#5321) (#5352) * manageiq_provider_info: new module * fix reference to manageiq.module * add missing alias in suboption * fix filename in botmeta * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * fix description of parameters * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * remove change applied on the wrong branch * fix the module name in metadata files * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * adjust RETURN documentation * adjust RETURN documentation indentation * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 32f9d78fa38255f4007b2aa8b3c3a9597a6803ca) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2022-10-12 11:32:26 +02:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2022, Alexei Znamensky <russoz@gmail.com>
# Copyright (c) 2017, Daniel Korn <korndaniel1@gmail.com>
# Copyright (c) 2017, Yaacov Zamir <yzamir@redhat.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = '''
module: manageiq_policies_info
version_added: 5.8.0
short_description: Listing of resource policy_profiles in ManageIQ
extends_documentation_fragment:
- community.general.manageiq
author: Alexei Znamensky (@russoz)
description:
- The manageiq_policies module supports listing policy_profiles in ManageIQ.
options:
resource_type:
type: str
description:
- The type of the resource to obtain the profile for.
required: true
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
'data store', 'group', 'resource pool', 'service', 'service template',
'template', 'tenant', 'user']
resource_name:
type: str
description:
- The name of the resource to obtain the profile for.
- Must be specified if I(resource_id) is not set. Both options are mutually exclusive.
resource_id:
type: int
description:
- The ID of the resource to obtain the profile for.
- Must be specified if I(resource_name) is not set. Both options are mutually exclusive.
'''
EXAMPLES = '''
- name: List current policy_profile and policies for a provider in ManageIQ
community.general.manageiq_policies_info:
resource_name: 'EngLab'
resource_type: 'provider'
manageiq_connection:
url: 'http://127.0.0.1:3000'
username: 'admin'
password: 'smartvm'
register: result
'''
RETURN = '''
profiles:
description:
- List current policy_profile and policies for a provider in ManageIQ.
returned: always
type: list
elements: dict
sample:
- policies:
- active: true
description: OpenSCAP
name: openscap policy
- active: true,
description: Analyse incoming container images
name: analyse incoming container images
- active: true
description: Schedule compliance after smart state analysis
name: schedule compliance after smart state analysis
profile_description: OpenSCAP profile
profile_name: openscap profile
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.manageiq import ManageIQ, manageiq_argument_spec, manageiq_entities
manageiq_policies_info: new module (#5321) (#5352) * manageiq_provider_info: new module * fix reference to manageiq.module * add missing alias in suboption * fix filename in botmeta * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * fix description of parameters * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * remove change applied on the wrong branch * fix the module name in metadata files * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * adjust RETURN documentation * adjust RETURN documentation indentation * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/remote_management/manageiq/manageiq_policies_info.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 32f9d78fa38255f4007b2aa8b3c3a9597a6803ca) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
2022-10-12 11:32:26 +02:00
def main():
argument_spec = dict(
resource_id=dict(required=False, type='int'),
resource_name=dict(required=False, type='str'),
resource_type=dict(required=True, type='str',
choices=list(manageiq_entities().keys())),
)
# add the manageiq connection arguments to the arguments
argument_spec.update(manageiq_argument_spec())
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[["resource_id", "resource_name"]],
required_one_of=[["resource_id", "resource_name"]],
supports_check_mode=True,
)
resource_id = module.params['resource_id']
resource_type_key = module.params['resource_type']
resource_name = module.params['resource_name']
# get the resource type
resource_type = manageiq_entities()[resource_type_key]
manageiq_policies = ManageIQ(module).policies(resource_id, resource_type, resource_name)
# return a list of current profiles for this object
current_profiles = manageiq_policies.query_resource_profiles()
res_args = dict(changed=False, profiles=current_profiles)
module.exit_json(**res_args)
if __name__ == "__main__":
main()