generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clickhouse_cfg_info: add the new module
- Loading branch information
1 parent
5385a27
commit 67cd2a6
Showing
5 changed files
with
1,059 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (c) 2024, Andrew Klychkov (@Andersson007) <andrew.a.klychkov@gmail.com> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
DOCUMENTATION = r''' | ||
--- | ||
module: clickhouse_cfg_info | ||
short_description: Retrieves ClickHouse config file content and returns it as JSON | ||
description: | ||
- Retrieves ClickHouse config file content and returns it as JSON. | ||
- Only config files in YAML format are supported at the moment. | ||
- Does not change server state. | ||
attributes: | ||
check_mode: | ||
description: Supports check_mode. | ||
support: full | ||
author: | ||
- Andrew Klychkov (@Andersson007) | ||
options: | ||
path: | ||
description: | ||
- Path to the config file. | ||
type: path | ||
required: true | ||
requirements: | ||
- pyyaml | ||
''' | ||
|
||
# TODO: add the "dir" option | ||
# mutually exclusive with path. | ||
# If specified, it'll search the cfg files | ||
# in that directory and in config.d directory there. | ||
# Let's discuss it first | ||
|
||
# TODO: it should also handle xml configs | ||
|
||
EXAMPLES = r''' | ||
- name: Get server information | ||
register: result | ||
community.clickhouse.clickhouse_cfg_info: | ||
path: /etc/clickhouse-server/config.yaml | ||
- name: Print returned data | ||
ansible.builtin.debug: | ||
var: result | ||
''' | ||
|
||
RETURN = r''' # ''' | ||
|
||
try: | ||
import yaml | ||
HAS_PYYAML = True | ||
except ImportError: | ||
HAS_PYYAML = False | ||
|
||
from ansible.module_utils.basic import ( | ||
AnsibleModule, | ||
missing_required_lib, | ||
) | ||
|
||
|
||
def load_from_yaml(path): | ||
with open(path, 'r') as f: | ||
content = yaml.safe_load(f) | ||
return content | ||
|
||
|
||
def main(): | ||
argument_spec = {} | ||
argument_spec.update( | ||
path=dict(type='path', required=True), | ||
) | ||
|
||
# Instantiate an object of module class | ||
module = AnsibleModule( | ||
argument_spec=argument_spec, | ||
supports_check_mode=True, | ||
) | ||
|
||
if not HAS_PYYAML: | ||
module.fail_json(msg=missing_required_lib('pyyaml')) | ||
|
||
cfg_content = load_from_yaml(module.params['path']) | ||
|
||
# Users will get this in JSON output after execution | ||
module.exit_json(changed=False, **cfg_content) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
clickhouse_driver | ||
pyyaml |
Oops, something went wrong.