Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clickhouse_cfg_info: add the new module #84

Merged
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
97 changes: 97 additions & 0 deletions plugins/modules/clickhouse_cfg_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/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

Andersson007 marked this conversation as resolved.
Show resolved Hide resolved
version_added: '0.7.0'

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: 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()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
clickhouse_driver
pyyaml
Loading
Loading