Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
mkdir -p .ansible/collections/ansible_collections/cloudera/cluster
git archive $(git rev-parse --abbrev-ref HEAD) | tar -x -C .ansible/collections/ansible_collections/cloudera/cluster
(cd .ansible/collections/ansible_collections/cloudera/cluster && pytest)

121 changes: 67 additions & 54 deletions plugins/modules/service_role_config_group_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
# Copyright 2025 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,38 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_utils import (
ClouderaManagerModule,
)

from ansible_collections.cloudera.cluster.plugins.module_utils.role_config_group_utils import (
parse_role_config_group_result,
)

from cm_client import (
ClustersResourceApi,
RoleConfigGroupsResourceApi,
ServicesResourceApi,
)
from cm_client.rest import ApiException


ANSIBLE_METADATA = {
"metadata_version": "1.1",
"status": ["preview"],
"supported_by": "community",
}

DOCUMENTATION = r"""
---
module: service_role_config_group_info
short_description: Retrieve information about a cluster service role config group or groups
description:
- Gather details about a role config group or groups of a service in a CDP cluster.
author:
- "Webster Mudge (@wmudge)"
requirements:
- cm_client
options:
cluster:
description:
Expand All @@ -61,23 +37,35 @@
required: yes
aliases:
- service_name
role_config_group:
type:
description:
- The role type defining the role config group(s).
- If specified, will return all role config groups for the type.
- Mutually exclusive with O(name).
type: str
aliases:
- role_type
name:
description:
- The role config group to examine.
- If undefined, the module will return all role config groups for the service.
- If defined, the module will return the role config group.
- If the role config group does not exist, the module will return an empty result.
type: str
required: yes
aliases:
- role_config_group
- name
extends_documentation_fragment:
- cloudera.cluster.cm_options
- cloudera.cluster.cm_endpoint
attributes:
check_mode:
support: full
requirements:
- cm-client
seealso:
- module: cloudera.cluster.service_role_config_group
"""

EXAMPLES = r"""
---
- name: Gather the configuration details for a cluster service role
cloudera.cluster.service_role_config_info:
host: "example.cloudera.internal"
Expand All @@ -99,47 +87,56 @@
"""

RETURN = r"""
---
role_config_groups:
description:
- List of service role config groups.
- List of cluster service role config groups.
type: list
elements: dict
returned: always
contains:
name:
description:
- The unique name of this role config group.
description: Name (identifier) of the role config group.
type: str
returned: always
role_type:
description:
- The type of the roles in this group.
description: The type of the roles in this role config group.
type: str
returned: always
base:
description:
- Flag indicating whether this is a base group.
description: Flag indicating whether this is a base role config group.
type: bool
returned: always
display_name:
description:
- A user-friendly name of the role config group, as would have been shown in the web UI.
description: A user-friendly name of the role config group, as would have been shown in the web UI.
type: str
returned: when supported
service_name:
description:
- The service name associated with this role config group.
description: The service name associated with this role config group.
type: str
returned: always
role_names:
description:
- List of role names associated with this role config group.
description: List of role names (identifiers) associated with this role config group.
type: list
elements: str
returned: when supported
"""

from cm_client import (
ClustersResourceApi,
RoleConfigGroupsResourceApi,
ServicesResourceApi,
)
from cm_client.rest import ApiException

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_utils import (
ClouderaManagerModule,
)

from ansible_collections.cloudera.cluster.plugins.module_utils.role_config_group_utils import (
parse_role_config_group_result,
get_base_role_config_group,
)


class ClusterServiceRoleConfigGroupInfo(ClouderaManagerModule):
def __init__(self, module):
Expand All @@ -148,7 +145,8 @@ def __init__(self, module):
# Set the parameters
self.cluster = self.get_param("cluster")
self.service = self.get_param("service")
self.role_config_group = self.get_param("role_config_group")
self.type = self.get_param("type")
self.name = self.get_param("name")

# Initialize the return values
self.output = []
Expand Down Expand Up @@ -176,30 +174,43 @@ def process(self):
else:
raise ex

api_instance = RoleConfigGroupsResourceApi(self.api_client)
rcg_api = RoleConfigGroupsResourceApi(self.api_client)

results = []
if self.role_config_group:

# If given a specific RCG
if self.name:
try:
results = [
api_instance.read_role_config_group(
rcg_api.read_role_config_group(
cluster_name=self.cluster,
role_config_group_name=self.role_config_group,
role_config_group_name=self.name,
service_name=self.service,
)
]
except ApiException as e:
if e.status != 404:
raise e
# Else if given a RCG type
elif self.type:
results = [
r
for r in rcg_api.read_role_config_groups(
cluster_name=self.cluster,
service_name=self.service,
).items
if r.role_type == self.type
]
# Else get all RCG entries for the given service
else:
results = api_instance.read_role_config_groups(
results = rcg_api.read_role_config_groups(
cluster_name=self.cluster,
service_name=self.service,
).items

# Get role membership
for r in results:
# Get role membership
roles = api_instance.read_roles(
roles = rcg_api.read_roles(
cluster_name=self.cluster,
service_name=self.service,
role_config_group_name=r.name,
Expand All @@ -218,8 +229,10 @@ def main():
argument_spec=dict(
cluster=dict(required=True, aliases=["cluster_name"]),
service=dict(required=True, aliases=["service_name"]),
role_config_group=dict(aliases=["role_config_group", "name"]),
type=dict(aliases=["role_type"]),
name=dict(aliases=["role_config_group"]),
),
mutually_exclusive=[["type", "name"]],
supports_check_mode=True,
)

Expand Down
10 changes: 2 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,29 @@ pattern = "version:\\s+(?P<version>[\\d\\.]+)"

[tool.hatch.envs.default]
python = "3.12"
skip-install = true
detached = true
dependencies = [
"pre-commit",
"coverage[toml]",
"pytest",
"pytest-mock",
# "pytest-cov",
"molecule",
"molecule-plugins",
"molecule-plugins[ec2]",
"tox-ansible",
"ansible-core<2.17", # For RHEL 8 support
"jmespath",
"cm-client",
]

[tool.hatch.envs.lint]
python = "3.12"
skip-install = true
detached = true
extra-dependencies = ["ansible-lint"]

[tool.hatch.envs.lint.scripts]
run = "pre-commit run -a"

[tool.pytest.ini_options]
# addopts = [
# "--lf",
# "--nf",
# ]
testpaths = ["tests"]
filterwarnings = [
"ignore:AnsibleCollectionFinder has already been configured",
Expand Down
Loading
Loading