From 0007986ea0887bf50de4e487076da1430f256725 Mon Sep 17 00:00:00 2001 From: NeoPlays <80448387+NeoPlays@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:17:08 +0200 Subject: [PATCH] different approach --- .../tasks/2.1.5/sdvt_changes.yaml | 8 +- .../tasks/2.1.5/updates-215.yaml | 91 ++++++------------- 2 files changed, 32 insertions(+), 67 deletions(-) diff --git a/controls/roles/update-changes/tasks/2.1.5/sdvt_changes.yaml b/controls/roles/update-changes/tasks/2.1.5/sdvt_changes.yaml index 8b18631535..2056580821 100644 --- a/controls/roles/update-changes/tasks/2.1.5/sdvt_changes.yaml +++ b/controls/roles/update-changes/tasks/2.1.5/sdvt_changes.yaml @@ -1,7 +1,7 @@ --- - name: Read service file slurp: - src: "{{ config_file.path }}" + src: "{{ config_file_path }}" register: service_configuration_raw - name: Parse service's configuration @@ -11,7 +11,7 @@ - name: Adjust Lodestar Config lineinfile: - path: "{{ config_file.path }}" + path: "{{ config_file_path }}" regexp: "--useProduceBlockV3" state: absent when: @@ -19,7 +19,7 @@ - name: Adjust Teku Config lineinfile: - path: "{{ config_file.path }}" + path: "{{ config_file_path }}" regexp: "--Xblock-v3-enabled" state: absent when: @@ -27,7 +27,7 @@ - name: Adjust Lighthouse Config lineinfile: - path: "{{ config_file.path }}" + path: "{{ config_file_path }}" regexp: "--produce-block-v3" state: absent when: diff --git a/controls/roles/update-changes/tasks/2.1.5/updates-215.yaml b/controls/roles/update-changes/tasks/2.1.5/updates-215.yaml index a3c172af24..f194cc1b72 100644 --- a/controls/roles/update-changes/tasks/2.1.5/updates-215.yaml +++ b/controls/roles/update-changes/tasks/2.1.5/updates-215.yaml @@ -1,77 +1,42 @@ ---- -- name: Find service configs - find: - paths: "/etc/stereum/services" - register: service_config_files - -- name: Include ValidatorEjector Changes - include_tasks: ValidatorEjector_changes.yaml - loop: "{{ service_config_files.files }}" - -- name: Find potential CharonService files - find: - paths: "/etc/stereum/services" - contains: "service: CharonService" - register: found_files +- name: Filter files that contain both regex patterns + shell: "grep -rlE 'service: CharonService' /etc/stereum/services | xargs grep -lE 'image: obolnetwork/charon:v1\\.[0-9]+\\.[0-9]+'" + register: grep_result + failed_when: false + changed_when: false -- name: Ensure found_files is not empty - assert: - that: found_files.matched > 0 - fail_msg: "No files found with 'service: CharonService'" - -- name: Read file content - slurp: - src: "{{ item.path }}" - register: file_content - loop: "{{ found_files.files }}" - when: found_files.matched > 0 - -- name: Initialize charon_service_files +- name: Set fact for filtered files set_fact: - charon_service_files: [] + filtered_files: "{{ grep_result.stdout_lines }}" -- name: Check for specific image pattern +- name: Extract UUIDs from filtered filenames set_fact: - charon_service_files: "{{ charon_service_files + [item.source] }}" - loop: "{{ file_content.results }}" - when: > - (item.content | b64decode | search('service: CharonService')) and - (item.content | b64decode | search('image: obolnetwork/charon:v1\\.[0-9]+\\.[0-9]+')) + uuids: "{{ filtered_files | map('basename') | map('regex_replace', '\\.yaml$', '') | list }}" -- name: Debug CharonService files - debug: - var: charon_service_files - -- name: Set Conditional - set_fact: - charonFound: "{{ charon_service_files.matched | default(0) > 0 }}" - -- name: Set CharonService ID - set_fact: - charon_service_id: "{{ charon_service_files.files[0].path | basename | splitext | first }}" - when: charonFound - -- name: Debug CharonService ID - debug: - var: charon_service_id - when: charonFound - -- name: Find service configs which contain CharonService ID +- name: Find all files in /etc/stereum/services find: paths: "/etc/stereum/services" - read_whole_file: true - contains: "{{ charon_service_id }}" - register: charon_service_config_files - when: charonFound + recurse: yes + patterns: "*.yaml" + register: all_files + +- name: Check if files contain any of the extracted UUIDs + shell: "grep -lE '{{ uuids | join('|') }}' {{ item.path }}" + with_items: "{{ all_files.files }}" + register: uuid_grep_result + failed_when: false + changed_when: false + +- name: Set fact for files containing UUIDs + set_fact: + files_with_uuids: "{{ uuid_grep_result.results | selectattr('rc', 'eq', 0) | map(attribute='item.path') | list }}" -- name: Debug CharonService config files +- name: Debug files with UUIDs debug: - var: charon_service_config_files - when: charonFound + var: files_with_uuids - name: Include SDVT Changes include_tasks: sdvt_changes.yaml - loop: "{{ charon_service_config_files.files }}" + loop: "{{ files_with_uuids }}" loop_control: - loop_var: config_file + loop_var: config_file_path when: charonFound