From ddf842f5b6fa0c4340be3b0f42b162661edece65 Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Tue, 24 Dec 2024 19:24:21 +0800 Subject: [PATCH 01/11] module, variable, initial steps --- plugins/modules/dynconfig_apply.py | 30 +++++++++++++++++++ roles/ydbd_dynamic/defaults/main.yaml | 3 ++ roles/ydbd_dynamic/tasks/main.yaml | 2 ++ .../templates/ydbd-dynnode.service | 2 ++ roles/ydbd_static/defaults/main.yaml | 3 ++ roles/ydbd_static/tasks/main.yaml | 17 +++++++++++ .../templates/ydbd-dyn-config.yaml.j2 | 15 ++++++++++ 7 files changed, 72 insertions(+) create mode 100644 plugins/modules/dynconfig_apply.py create mode 100644 roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 diff --git a/plugins/modules/dynconfig_apply.py b/plugins/modules/dynconfig_apply.py new file mode 100644 index 0000000..d393d81 --- /dev/null +++ b/plugins/modules/dynconfig_apply.py @@ -0,0 +1,30 @@ +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ydb_platform.ydb.plugins.module_utils import cli + + +def main(): + argument_spec=dict( + config=dict(type='str', default=""), + ) + cli.YDB.add_arguments(argument_spec) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) + configFilename = module.params.get('config') + result = {'changed': False} + try: + ydb_cli = cli.YDB.from_module(module) + rc, stdout, stderr = ydb_cli(['admin', 'config', 'replace','-f',configFilename]) + if rc != 0: + result['msg'] = f'command: "ydb admin config replace" failed' + result['stderr'] = stderr + module.fail_json(**result) + + result['msg'] = 'command: "ydb admin config replace" succeeded' + module.exit_json(**result) + + except Exception as e: + result['msg'] = f'unexpected exception: {e}' + module.fail_json(**result) + + +if __name__ == '__main__': + main() diff --git a/roles/ydbd_dynamic/defaults/main.yaml b/roles/ydbd_dynamic/defaults/main.yaml index bce95b7..d313228 100644 --- a/roles/ydbd_dynamic/defaults/main.yaml +++ b/roles/ydbd_dynamic/defaults/main.yaml @@ -1,2 +1,5 @@ ydb_database_groups: 1 ydb_request_client_certificate: false +# ydb_dynamic_config - use dynamic configs instead of static configs +# Default value: false +ydb_dynamic_config: false diff --git a/roles/ydbd_dynamic/tasks/main.yaml b/roles/ydbd_dynamic/tasks/main.yaml index f7d8acf..df9095c 100644 --- a/roles/ydbd_dynamic/tasks/main.yaml +++ b/roles/ydbd_dynamic/tasks/main.yaml @@ -10,10 +10,12 @@ - ydb_brokers - ydb_dbname - ydb_dynnodes + - ydb_dynamic_config - name: create dynamic node configuration file command: "{{ ydb_dir }}/home/update_config_file.sh ydbd-config.yaml ydbd-config-dynamic.yaml COMPUTE {{ ydb_cores_dynamic }}" changed_when: false + when: not ydb_dynamic_config|bool - name: create dynamic node systemd unit template: diff --git a/roles/ydbd_dynamic/templates/ydbd-dynnode.service b/roles/ydbd_dynamic/templates/ydbd-dynnode.service index e40c693..94c59ca 100644 --- a/roles/ydbd_dynamic/templates/ydbd-dynnode.service +++ b/roles/ydbd_dynamic/templates/ydbd-dynnode.service @@ -11,7 +11,9 @@ User=ydb PermissionsStartOnly=true Environment=LD_LIBRARY_PATH={{ ydb_dir }}/lib ExecStart={{ ydb_dir }}/bin/ydbd server \ +{% if not ydb_dynamic_config|bool %} --yaml-config {{ ydb_dir }}/cfg/ydbd-config-dynamic.yaml \ +{% endif %} --grpcs-port {{ 2136 + item.offset }} --grpc-ca {{ ydb_dir }}/certs/ca.crt \ --ic-port {{ 19002 + item.offset }} --ca {{ ydb_dir }}/certs/ca.crt \ --mon-port {{ 8766 + item.offset }} --mon-cert {{ ydb_dir }}/certs/web.pem \ diff --git a/roles/ydbd_static/defaults/main.yaml b/roles/ydbd_static/defaults/main.yaml index 18e0be6..59aa313 100644 --- a/roles/ydbd_static/defaults/main.yaml +++ b/roles/ydbd_static/defaults/main.yaml @@ -1,3 +1,6 @@ ydb_allow_format_drives: false ydb_skip_data_loss_confirmation_prompt: false ydb_enforce_user_token_requirement: true +# ydb_dynamic_config - use dynamic configs instead of static configs +# Default value: false +ydb_dynamic_config: false diff --git a/roles/ydbd_static/tasks/main.yaml b/roles/ydbd_static/tasks/main.yaml index a77575d..a2a0d00 100644 --- a/roles/ydbd_static/tasks/main.yaml +++ b/roles/ydbd_static/tasks/main.yaml @@ -17,6 +17,7 @@ - ydb_disks - ydb_domain - ydb_user + - ydb_dynamic_config - name: check if required secrets are defined no_log: true @@ -45,6 +46,9 @@ - name: Add the database creation script template: src=create_database.j2 dest={{ ydb_dir }}/home/create_database.sh mode='755' +- name: Add the dyn config + template: src=ydbd-dyn-config.yaml.j2 dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' + - name: create static node configuration file command: "{{ ydb_dir }}/home/update_config_file.sh ydbd-config.yaml ydbd-config-static.yaml STORAGE {{ ydb_cores_static }}" changed_when: false @@ -180,3 +184,16 @@ new_password: "{{ ydb_password }}" token: "{{ ydb_credentials.token }}" run_once: true + +- name: Configure dyn config + ydb_platform.ydb.dynconfig_apply: + ydb_bin: "{{ ydb_dir }}/bin/ydb" + ld_library_path: "{{ ydb_dir }}/lib" + ca_file: "{{ ydb_dir }}/certs/ca.crt" + endpoint: "grpcs://{{ inventory_hostname }}:2135" + database: "/{{ ydb_domain }}" + user: "{{ ydb_user }}" + token: "{{ ydb_credentials.token }}" + config: "{{ ydb_dir }}/cfg/ydbd-dyn-config.yaml" + when: ydb_dynamic_config|bool + run_once: true \ No newline at end of file diff --git a/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 new file mode 100644 index 0000000..f62d703 --- /dev/null +++ b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 @@ -0,0 +1,15 @@ +metadata: + cluster: "" + version: 0 +config: +# This parameter must be set in 'true' + yaml_config_enabled: true + actor_system_config: +# Auto configure node by using number of CPU cores + use_auto_config: true +# Type of the node (HYBRID, COMPUTE, STORAGE) + node_type: COMPUTE +# Number of CPU cores + cpu_count: {{ ydb_cores_dynamic }} +allowed_labels: {} +selector_config: [] From 49a3e08634a7392f6e39ac1dde39dc46075a75dd Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Wed, 25 Dec 2024 14:12:19 +0800 Subject: [PATCH 02/11] +custom dynconfig --- roles/ydbd_dynamic/defaults/main.yaml | 4 ++-- roles/ydbd_dynamic/tasks/main.yaml | 4 ++-- roles/ydbd_dynamic/templates/ydbd-dynnode.service | 2 +- roles/ydbd_static/defaults/main.yaml | 8 ++++++-- roles/ydbd_static/tasks/main.yaml | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/roles/ydbd_dynamic/defaults/main.yaml b/roles/ydbd_dynamic/defaults/main.yaml index d313228..1216e56 100644 --- a/roles/ydbd_dynamic/defaults/main.yaml +++ b/roles/ydbd_dynamic/defaults/main.yaml @@ -1,5 +1,5 @@ ydb_database_groups: 1 ydb_request_client_certificate: false -# ydb_dynamic_config - use dynamic configs instead of static configs +# ydb_use_dynamic_config - define how to configure dynamic nodes - static or dynamic configs # Default value: false -ydb_dynamic_config: false +ydb_use_dynamic_config: false diff --git a/roles/ydbd_dynamic/tasks/main.yaml b/roles/ydbd_dynamic/tasks/main.yaml index df9095c..addbfce 100644 --- a/roles/ydbd_dynamic/tasks/main.yaml +++ b/roles/ydbd_dynamic/tasks/main.yaml @@ -10,12 +10,12 @@ - ydb_brokers - ydb_dbname - ydb_dynnodes - - ydb_dynamic_config + - ydb_use_dynamic_config - name: create dynamic node configuration file command: "{{ ydb_dir }}/home/update_config_file.sh ydbd-config.yaml ydbd-config-dynamic.yaml COMPUTE {{ ydb_cores_dynamic }}" changed_when: false - when: not ydb_dynamic_config|bool + when: not ydb_use_dynamic_config|bool - name: create dynamic node systemd unit template: diff --git a/roles/ydbd_dynamic/templates/ydbd-dynnode.service b/roles/ydbd_dynamic/templates/ydbd-dynnode.service index 924cd2e..a8fb797 100644 --- a/roles/ydbd_dynamic/templates/ydbd-dynnode.service +++ b/roles/ydbd_dynamic/templates/ydbd-dynnode.service @@ -12,7 +12,7 @@ UMask=077 PermissionsStartOnly=true Environment=LD_LIBRARY_PATH={{ ydb_dir }}/lib ExecStart={{ ydb_dir }}/bin/ydbd server \ -{% if not ydb_dynamic_config|bool %} +{% if not ydb_use_dynamic_config|bool %} --yaml-config {{ ydb_dir }}/cfg/ydbd-config-dynamic.yaml \ {% endif %} --grpcs-port {{ 2136 + item.offset }} --grpc-ca {{ ydb_dir }}/certs/ca.crt \ diff --git a/roles/ydbd_static/defaults/main.yaml b/roles/ydbd_static/defaults/main.yaml index 59aa313..2fa86f4 100644 --- a/roles/ydbd_static/defaults/main.yaml +++ b/roles/ydbd_static/defaults/main.yaml @@ -1,6 +1,10 @@ ydb_allow_format_drives: false ydb_skip_data_loss_confirmation_prompt: false ydb_enforce_user_token_requirement: true -# ydb_dynamic_config - use dynamic configs instead of static configs +# ydb_use_dynamic_config - define how to configure dynamic nodes - static or dynamic configs # Default value: false -ydb_dynamic_config: false +ydb_use_dynamic_config: false + +# ydb_dynamic_config - path to a custom dynamic config file +# Default value: ansible/roles/ydb_static/ydb-din-config.yaml.j2 +ydb_dynamic_config: ydb-din-config.yaml.j2 \ No newline at end of file diff --git a/roles/ydbd_static/tasks/main.yaml b/roles/ydbd_static/tasks/main.yaml index a2a0d00..a3b83f2 100644 --- a/roles/ydbd_static/tasks/main.yaml +++ b/roles/ydbd_static/tasks/main.yaml @@ -18,6 +18,7 @@ - ydb_domain - ydb_user - ydb_dynamic_config + - ydb_use_dynamic_config - name: check if required secrets are defined no_log: true @@ -47,7 +48,7 @@ template: src=create_database.j2 dest={{ ydb_dir }}/home/create_database.sh mode='755' - name: Add the dyn config - template: src=ydbd-dyn-config.yaml.j2 dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' + template: src={{ ydb_dynamic_config }} dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' - name: create static node configuration file command: "{{ ydb_dir }}/home/update_config_file.sh ydbd-config.yaml ydbd-config-static.yaml STORAGE {{ ydb_cores_static }}" @@ -195,5 +196,5 @@ user: "{{ ydb_user }}" token: "{{ ydb_credentials.token }}" config: "{{ ydb_dir }}/cfg/ydbd-dyn-config.yaml" - when: ydb_dynamic_config|bool + when: ydb_use_dynamic_config|bool run_once: true \ No newline at end of file From 6c94806f0cf9c27eca0e170c68466f62d8b1198b Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Thu, 26 Dec 2024 20:40:55 +0800 Subject: [PATCH 03/11] Fixes --- roles/install_ydbd/tasks/install_ydb_using_binary.yaml | 2 ++ roles/ydbd_static/defaults/main.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml index 45962c2..bdbd35c 100644 --- a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml +++ b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml @@ -35,6 +35,7 @@ dest: "{{ ydb_dir }}/release/{{ ydb_version }}/bin/ydbd" mode: 0755 follow: true + force: "{{ ydb_force_update }}" - name: copy YDB cli binary file ansible.builtin.copy: @@ -42,6 +43,7 @@ dest: "{{ ydb_dir }}/release/{{ ydb_version }}/bin/ydb" mode: 0755 follow: true + force: "{{ ydb_force_update }}" - name: Symlink the YDB binaries file: path="{{ ydb_dir }}/bin" diff --git a/roles/ydbd_static/defaults/main.yaml b/roles/ydbd_static/defaults/main.yaml index 2fa86f4..99367db 100644 --- a/roles/ydbd_static/defaults/main.yaml +++ b/roles/ydbd_static/defaults/main.yaml @@ -7,4 +7,4 @@ ydb_use_dynamic_config: false # ydb_dynamic_config - path to a custom dynamic config file # Default value: ansible/roles/ydb_static/ydb-din-config.yaml.j2 -ydb_dynamic_config: ydb-din-config.yaml.j2 \ No newline at end of file +ydb_dynamic_config: ydbd-dyn-config.yaml.j2 \ No newline at end of file From 19d5474ede0b224225c20016e4d5c8b89ceb6f2a Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Fri, 27 Dec 2024 23:39:21 +0800 Subject: [PATCH 04/11] Dyn config support --- plugins/modules/dynconfig_version.py | 40 +++++++++++++++++++ .../tasks/install_ydb_from_version.yaml | 1 + roles/install_ydbd/tasks/main.yaml | 2 +- roles/ydbd_static/tasks/main.yaml | 38 ++++++++++++------ .../templates/ydbd-dyn-config.yaml.j2 | 3 +- 5 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 plugins/modules/dynconfig_version.py diff --git a/plugins/modules/dynconfig_version.py b/plugins/modules/dynconfig_version.py new file mode 100644 index 0000000..2b84dcd --- /dev/null +++ b/plugins/modules/dynconfig_version.py @@ -0,0 +1,40 @@ +import re + +# +# This module returns current version of dynamic config +# The result is stored in 'version' variable of returning dict + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ydb_platform.ydb.plugins.module_utils import cli + +def main(): + argument_spec=dict( + timeout=dict(type='int', default=180), + ) + cli.YDB.add_arguments(argument_spec) + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) + result = {'changed': False} + try: + ydb_cmd = ['admin', 'config', 'fetch'] + ydb_cli = cli.YDB.from_module(module) + rc, stdout, stderr = ydb_cli(ydb_cmd) + if rc != 0: + result['msg'] = f'command: "ydb admin config fetch" failed' + result['stderr'] = stderr + module.fail_json(**result) + else: + version = 0 + match = re.search(r'version:\s*(\d+)', stdout) + if match: + version = int(match.group(1)) + result['msg'] = '' + result['version'] = version + module.exit_json(**result) + + except Exception as e: + result['msg'] = f'unexpected exception: {e}' + module.fail_json(**result) + + +if __name__ == '__main__': + main() diff --git a/roles/install_ydbd/tasks/install_ydb_from_version.yaml b/roles/install_ydbd/tasks/install_ydb_from_version.yaml index 48576c2..846a9b6 100644 --- a/roles/install_ydbd/tasks/install_ydb_from_version.yaml +++ b/roles/install_ydbd/tasks/install_ydb_from_version.yaml @@ -5,6 +5,7 @@ - name: Set local path to ydb_archive variable set_fact: ydb_archive: "{{ ydb_archive_dest }}ydbd-{{ ydb_version }}-linux-amd64.tar.gz" + when: ydb_archive is not defined - name: check if YDB release archive present delegate_to: 127.0.0.1 diff --git a/roles/install_ydbd/tasks/main.yaml b/roles/install_ydbd/tasks/main.yaml index 4a14d94..64f52ce 100644 --- a/roles/install_ydbd/tasks/main.yaml +++ b/roles/install_ydbd/tasks/main.yaml @@ -23,7 +23,7 @@ - name: download and install YDB server binary package from a release version number import_tasks: file: install_ydb_from_version.yaml - when: ydb_version is defined and ydbd_binary is not defined + when: ydb_version is defined and ydbd_binary is not defined and ydb_archive is not defined - name: install YDB server binary package from source code import_tasks: diff --git a/roles/ydbd_static/tasks/main.yaml b/roles/ydbd_static/tasks/main.yaml index a3b83f2..dfdfcec 100644 --- a/roles/ydbd_static/tasks/main.yaml +++ b/roles/ydbd_static/tasks/main.yaml @@ -47,9 +47,6 @@ - name: Add the database creation script template: src=create_database.j2 dest={{ ydb_dir }}/home/create_database.sh mode='755' -- name: Add the dyn config - template: src={{ ydb_dynamic_config }} dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' - - name: create static node configuration file command: "{{ ydb_dir }}/home/update_config_file.sh ydbd-config.yaml ydbd-config-static.yaml STORAGE {{ ydb_cores_static }}" changed_when: false @@ -186,15 +183,30 @@ token: "{{ ydb_credentials.token }}" run_once: true -- name: Configure dyn config - ydb_platform.ydb.dynconfig_apply: - ydb_bin: "{{ ydb_dir }}/bin/ydb" - ld_library_path: "{{ ydb_dir }}/lib" - ca_file: "{{ ydb_dir }}/certs/ca.crt" - endpoint: "grpcs://{{ inventory_hostname }}:2135" - database: "/{{ ydb_domain }}" - user: "{{ ydb_user }}" - token: "{{ ydb_credentials.token }}" - config: "{{ ydb_dir }}/cfg/ydbd-dyn-config.yaml" +- name: Dynamic configs + block: + - name: Get the current dynconfig version + ydb_platform.ydb.dynconfig_version: + ydb_bin: "{{ ydb_dir }}/bin/ydb" + ld_library_path: "{{ ydb_dir }}/lib" + ca_file: "{{ ydb_dir }}/certs/ca.crt" + endpoint: "grpcs://{{ inventory_hostname }}:2135" + database: "/{{ ydb_domain }}" + token: "{{ ydb_credentials.token }}" + register: ydb_dynconfig_info + + - name: Add the dyn config + template: src={{ ydb_dynamic_config }} dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' + + - name: Configure dyn config + ydb_platform.ydb.dynconfig_apply: + ydb_bin: "{{ ydb_dir }}/bin/ydb" + ld_library_path: "{{ ydb_dir }}/lib" + ca_file: "{{ ydb_dir }}/certs/ca.crt" + endpoint: "grpcs://{{ inventory_hostname }}:2135" + database: "/{{ ydb_domain }}" + user: "{{ ydb_user }}" + token: "{{ ydb_credentials.token }}" + config: "{{ ydb_dir }}/cfg/ydbd-dyn-config.yaml" when: ydb_use_dynamic_config|bool run_once: true \ No newline at end of file diff --git a/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 index f62d703..a06b4dc 100644 --- a/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 +++ b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 @@ -1,6 +1,6 @@ metadata: cluster: "" - version: 0 + version: {{ ydb_dynconfig_info['version'] }} config: # This parameter must be set in 'true' yaml_config_enabled: true @@ -11,5 +11,6 @@ config: node_type: COMPUTE # Number of CPU cores cpu_count: {{ ydb_cores_dynamic }} +{{ lookup('ansible.builtin.file', '{{ ydb_config }}') | indent( width=2, first=True) }} allowed_labels: {} selector_config: [] From 216f617b9df40d1f6fced21472e3f0c3216ec72c Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Sat, 28 Dec 2024 16:17:06 +0800 Subject: [PATCH 05/11] Get current dynconfig version --- plugins/modules/dynconfig_version.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/modules/dynconfig_version.py b/plugins/modules/dynconfig_version.py index 2b84dcd..abbabe4 100644 --- a/plugins/modules/dynconfig_version.py +++ b/plugins/modules/dynconfig_version.py @@ -13,23 +13,21 @@ def main(): ) cli.YDB.add_arguments(argument_spec) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False) - result = {'changed': False} + result = {'changed': False, 'version': 0} try: ydb_cmd = ['admin', 'config', 'fetch'] ydb_cli = cli.YDB.from_module(module) rc, stdout, stderr = ydb_cli(ydb_cmd) if rc != 0: + # We get 1 exit code if no YAML config in cluster result['msg'] = f'command: "ydb admin config fetch" failed' - result['stderr'] = stderr - module.fail_json(**result) else: - version = 0 match = re.search(r'version:\s*(\d+)', stdout) if match: version = int(match.group(1)) + result['version'] = version result['msg'] = '' - result['version'] = version - module.exit_json(**result) + module.exit_json(**result) except Exception as e: result['msg'] = f'unexpected exception: {e}' From 41b0151fa1dc685a2f8309838c2ac68578e9d484 Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Sat, 28 Dec 2024 16:17:22 +0800 Subject: [PATCH 06/11] Fix problem with PDisks --- plugins/modules/init_storage.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/modules/init_storage.py b/plugins/modules/init_storage.py index 5465316..423ae68 100644 --- a/plugins/modules/init_storage.py +++ b/plugins/modules/init_storage.py @@ -48,6 +48,14 @@ def main(): result['stdout'] = stdout result['stderr'] = stderr module.fail_json(**result) + + # Check PDisk status + rc, stdout, stderr = ydb_dstool(['pdisk', 'list', '--format=json']) + if rc == 0: + dstool_result = json.loads(stdout)[0] + for pdisk in dstool_result: + if pdisk["Status"] != "ACTIVE": + rc = ydb_dstool(['pdisk', 'set', '--status=ACTIVE','--pdisk-ids',pdisk["NodeId:PDiskId"]]) result['changed'] = True result['msg'] = 'blobstorage config init succeeded' From 568a24f5e7c3f98f5143ae97901b51396d3e39ad Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Sat, 28 Dec 2024 16:17:57 +0800 Subject: [PATCH 07/11] Create dynamic config + common config like template --- roles/install_ydbd/tasks/install_ydb_using_binary.yaml | 6 ------ roles/install_ydbd/tasks/main.yaml | 7 +++++++ roles/preflight/tasks/main.yaml | 5 +++++ roles/ydbd/tasks/main.yaml | 2 +- roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml index bdbd35c..1a6f1ed 100644 --- a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml +++ b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml @@ -51,10 +51,4 @@ state=link force=yes -- name: Create the YDB CLI default binary directory - file: state=directory path={{ ydb_dir }}/home/ydb/bin recurse=true group=ydb owner=ydb mode='0700' - -- name: Disable YDB CLI version checks - copy: src=ydb-cli-config.json dest={{ ydb_dir }}/home/ydb/bin/config.json group=ydb owner=ydb mode='0644' - register: ydb_is_installed diff --git a/roles/install_ydbd/tasks/main.yaml b/roles/install_ydbd/tasks/main.yaml index 64f52ce..252748b 100644 --- a/roles/install_ydbd/tasks/main.yaml +++ b/roles/install_ydbd/tasks/main.yaml @@ -34,3 +34,10 @@ import_tasks: file: install_ydb_using_binary.yaml when: ydbd_binary is defined and ydb_cli_binary is defined + +- name: Create the YDB CLI default binary directory + file: state=directory path={{ ydb_dir }}/home/ydb/bin recurse=true group=ydb owner=ydb mode='0700' + +- name: Disable YDB CLI version checks + copy: src=ydb-cli-config.json dest={{ ydb_dir }}/home/ydb/bin/config.json group=ydb owner=ydb mode='0644' + register: ydb_is_installed diff --git a/roles/preflight/tasks/main.yaml b/roles/preflight/tasks/main.yaml index 889e3e5..bbde126 100644 --- a/roles/preflight/tasks/main.yaml +++ b/roles/preflight/tasks/main.yaml @@ -37,3 +37,8 @@ - name: Check current user ansible.builtin.command: whoami register: current_user + +- name: Check conditions in variables (1. dynamic config) + ansible.builtin.fail: + msg: "Impossible to use ydb_enforce_user_token_requirement and ydb_request_client_certificate together" + when: ydb_enforce_user_token_requirement|bool and ydb_request_client_certificate|bool diff --git a/roles/ydbd/tasks/main.yaml b/roles/ydbd/tasks/main.yaml index c4004ce..de455c1 100644 --- a/roles/ydbd/tasks/main.yaml +++ b/roles/ydbd/tasks/main.yaml @@ -104,7 +104,7 @@ mode: 0440 - name: copy configuration file - copy: + ansible.builtin.template: src: "{{ ydb_config }}" dest: "{{ ydb_dir }}/cfg/ydbd-config.yaml" owner: root diff --git a/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 index a06b4dc..2f04d2e 100644 --- a/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 +++ b/roles/ydbd_static/templates/ydbd-dyn-config.yaml.j2 @@ -11,6 +11,6 @@ config: node_type: COMPUTE # Number of CPU cores cpu_count: {{ ydb_cores_dynamic }} -{{ lookup('ansible.builtin.file', '{{ ydb_config }}') | indent( width=2, first=True) }} +{{ lookup('ansible.builtin.template', '{{ ydb_config }}') | indent( width=2, first=True) }} allowed_labels: {} selector_config: [] From a31e4c4d9a66701ede3a32834923d61e0f9bdfd2 Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Sat, 28 Dec 2024 17:46:44 +0800 Subject: [PATCH 08/11] Update plugins/modules/init_storage.py Co-authored-by: Ivan Blinkov --- plugins/modules/init_storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/init_storage.py b/plugins/modules/init_storage.py index 423ae68..a6cc172 100644 --- a/plugins/modules/init_storage.py +++ b/plugins/modules/init_storage.py @@ -55,7 +55,7 @@ def main(): dstool_result = json.loads(stdout)[0] for pdisk in dstool_result: if pdisk["Status"] != "ACTIVE": - rc = ydb_dstool(['pdisk', 'set', '--status=ACTIVE','--pdisk-ids',pdisk["NodeId:PDiskId"]]) + rc = ydb_dstool(['pdisk', 'set', '--status=ACTIVE', '--pdisk-ids', pdisk["NodeId:PDiskId"]]) result['changed'] = True result['msg'] = 'blobstorage config init succeeded' From 744b9c2bdfd08ec185a50e574598dc8b045d663c Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Thu, 9 Jan 2025 18:56:12 +0800 Subject: [PATCH 09/11] Remove dupes --- roles/install_ydbd/tasks/install_ydb_using_binary.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml index f174021..a840eeb 100644 --- a/roles/install_ydbd/tasks/install_ydb_using_binary.yaml +++ b/roles/install_ydbd/tasks/install_ydb_using_binary.yaml @@ -36,7 +36,6 @@ mode: 0755 follow: true force: "{{ ydb_force_update }}" - force: "{{ ydb_force_update }}" - name: copy YDB cli binary file ansible.builtin.copy: @@ -45,7 +44,6 @@ mode: 0755 follow: true force: "{{ ydb_force_update }}" - force: "{{ ydb_force_update }}" - name: Symlink the YDB binaries file: path="{{ ydb_dir }}/bin" From 101028aa5b61663ed4ffb60112ae6800d33844de Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Fri, 17 Jan 2025 16:09:57 +0800 Subject: [PATCH 10/11] +documentation --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index eccc82d..556c4da 100644 --- a/README.md +++ b/README.md @@ -276,3 +276,22 @@ sudo docker run -it --rm \ -v /home/ansible/ydb-ansible:/root/.ansible/collections/ansible_collections/ydb_platform/ydb \ ydb-ansible ansible-console ydb ``` +# Dynamic config + +Dynamic config (https://ydb.tech/docs/en/maintenance/manual/dynamic-config) allows to configure dynamic nodes without local configs. + +To use dynamic configs you will have to turn off `ydb_enforce_user_token_requirement` and set `ydb_use_dynamic_config` in `true`. + +You can define your own dynamic config. In this case you can take `roles/ydb_static/templates/ydb-din-config.yaml.j2` as an example and make appropriate changes. + +```YAML + ydb_enforce_user_token_requirement: false + + # ydb_use_dynamic_config - define how to configure dynamic nodes - static or dynamic configs + # Default value: false + ydb_use_dynamic_config: true + + # ydb_dynamic_config - path to a custom dynamic config file + # Default value: ansible/roles/ydb_static/templates/ydb-din-config.yaml.j2 + # ydb_dynamic_config: +``` \ No newline at end of file From e1c98e0cd5a8185e68a48981db0606f5bb9000b2 Mon Sep 17 00:00:00 2001 From: Eugene Arbatsky Date: Tue, 21 Jan 2025 16:22:50 +0800 Subject: [PATCH 11/11] remove variable --- README.md | 4 ---- roles/ydbd_static/defaults/main.yaml | 4 ---- roles/ydbd_static/tasks/main.yaml | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 556c4da..9c4b919 100644 --- a/README.md +++ b/README.md @@ -290,8 +290,4 @@ You can define your own dynamic config. In this case you can take `roles/ydb_sta # ydb_use_dynamic_config - define how to configure dynamic nodes - static or dynamic configs # Default value: false ydb_use_dynamic_config: true - - # ydb_dynamic_config - path to a custom dynamic config file - # Default value: ansible/roles/ydb_static/templates/ydb-din-config.yaml.j2 - # ydb_dynamic_config: ``` \ No newline at end of file diff --git a/roles/ydbd_static/defaults/main.yaml b/roles/ydbd_static/defaults/main.yaml index 99367db..db1c172 100644 --- a/roles/ydbd_static/defaults/main.yaml +++ b/roles/ydbd_static/defaults/main.yaml @@ -4,7 +4,3 @@ ydb_enforce_user_token_requirement: true # ydb_use_dynamic_config - define how to configure dynamic nodes - static or dynamic configs # Default value: false ydb_use_dynamic_config: false - -# ydb_dynamic_config - path to a custom dynamic config file -# Default value: ansible/roles/ydb_static/ydb-din-config.yaml.j2 -ydb_dynamic_config: ydbd-dyn-config.yaml.j2 \ No newline at end of file diff --git a/roles/ydbd_static/tasks/main.yaml b/roles/ydbd_static/tasks/main.yaml index dfdfcec..662b215 100644 --- a/roles/ydbd_static/tasks/main.yaml +++ b/roles/ydbd_static/tasks/main.yaml @@ -196,7 +196,7 @@ register: ydb_dynconfig_info - name: Add the dyn config - template: src={{ ydb_dynamic_config }} dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' + template: src=ydbd-dyn-config.yaml.j2 dest={{ ydb_dir }}/cfg/ydbd-dyn-config.yaml mode='640' - name: Configure dyn config ydb_platform.ydb.dynconfig_apply: