Debian Codegraph @

ansible_collections/kubernetes/core/plugins/modules/helm_plugin_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10
11 DOCUMENTATION = r"""
12 ---
13 module: helm_plugin_info
14 short_description: Gather information about Helm plugins
15 version_added: 1.0.0
16 author:
17 - Abhijeet Kasurde (@Akasurde)
18 requirements:
19 - "helm >= 3.0.0 (https://github.com/helm/helm/releases)"
20 description:
21 - Gather information about Helm plugins installed in namespace.
22 options:
23 #Helm options
24 plugin_name:
25 description:
26 - Name of Helm plugin, to gather particular plugin info.
27 type: str
28 extends_documentation_fragment:
29 - kubernetes.core.helm_common_options
30 """
31
32 EXAMPLES = r"""
33 - name: Gather Helm plugin info
34 kubernetes.core.helm_plugin_info:
35
36 - name: Gather Helm env plugin info
37 kubernetes.core.helm_plugin_info:
38 plugin_name: env
39 """
40
41 RETURN = r"""
42 stdout:
43 type: str
44 description: Full `helm` command stdout, in case you want to display it or examine the event log
45 returned: always
46 sample: ''
47 stderr:
48 type: str
49 description: Full `helm` command stderr, in case you want to display it or examine the event log
50 returned: always
51 sample: ''
52 command:
53 type: str
54 description: Full `helm` command built by this module, in case you want to re-run the command outside the module or debug a problem.
55 returned: always
56 sample: helm plugin list ...
57 plugin_list:
58 type: list
59 description: Helm plugin dict inside a list
60 returned: always
61 sample: {
62 "name": "env",
63 "version": "0.1.0",
64 "description": "Print out the helm environment."
65 }
66 rc:
67 type: int
68 description: Helm plugin command return code
69 returned: always
70 sample: 1
71 """
72
73 import copy
74
75 from ansible_collections.kubernetes.core.plugins.module_utils.helm import (
76 AnsibleHelmModule,
77 parse_helm_plugin_list,
78 )
79 from ansible_collections.kubernetes.core.plugins.module_utils.helm_args_common import (
80 HELM_AUTH_ARG_SPEC,
81 HELM_AUTH_MUTUALLY_EXCLUSIVE,
82 )
83
84
85 def main():
86 argument_spec = copy.deepcopy(HELM_AUTH_ARG_SPEC)
87 argument_spec.update(
88 dict(
89 plugin_name=dict(
90 type="str",
91 ),
92 )
93 )
94
95 module = AnsibleHelmModule(
96 argument_spec=argument_spec,
97 mutually_exclusive=HELM_AUTH_MUTUALLY_EXCLUSIVE,
98 supports_check_mode=True,
99 )
100
101 # Validate helm version >= 3.0.0
102 module.validate_helm_version()
103
104 plugin_name = module.params.get("plugin_name")
105
106 rc, output, err, command = module.get_helm_plugin_list()
107
108 plugins = parse_helm_plugin_list(output=output.splitlines())
109 if plugin_name is not None:
110 plugins = [plugin for plugin in plugins if plugin.get("name") == plugin_name]
111
112 module.exit_json(
113 changed=True,
114 command=command,
115 stdout=output,
116 stderr=err,
117 rc=rc,
118 plugin_list=plugins,
119 )
120
121
122 if __name__ == "__main__":
123 main()