From ab8ecbb2824ab5d14831ae19e60d967551cf30ff Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Mon, 20 Jul 2026 15:56:06 +0200 Subject: [PATCH] ansible: extract getting ioc port into utils and use it in ioc-start --- ansible/tasks/ioc/ioc-install.yml | 32 ++-------------------------- ansible/tasks/ioc/ioc-start.yml | 3 +++ ansible/tasks/utils/get-ioc-port.yml | 26 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 ansible/tasks/utils/get-ioc-port.yml diff --git a/ansible/tasks/ioc/ioc-install.yml b/ansible/tasks/ioc/ioc-install.yml index 1681c04..ff930fe 100644 --- a/ansible/tasks/ioc/ioc-install.yml +++ b/ansible/tasks/ioc/ioc-install.yml @@ -1,40 +1,12 @@ --- -- name: Clone this repository - ansible.builtin.git: - repo: "git@gitea.psi.ch:sls/hla_framework_bd.git" - dest: "{{ workspace_dir }}" - accept_hostkey: true - version: "{{ branch_name }}" - force: true +- name: Clone repo and get/set ioc_port + ansible.builtin.import_tasks: ../utils/get-ioc-port.yml - name: Initialize service name ansible.builtin.set_fact: # Uses preferred_service_name_lower if defined in vars, otherwise falls back to the CLI extra-vars target_service_name_lower: "{{ preferred_service_name_lower | default(service_name_lower) }}" -- name: Initialize service name - ansible.builtin.set_fact: - # Uses preferred_service_name_lower if defined in vars, otherwise falls back to the CLI extra-vars - target_service_name_lower: "{{ preferred_service_name_lower | default(service_name_lower) }}" - -- name: Read the service registry file - ansible.builtin.slurp: - src: "{{ workspace_dir }}/config/services_registry.yml" - register: remote_registry_file - -- name: Parse the service registry YAML content into a fact - ansible.builtin.set_fact: - services_registry: "{{ remote_registry_file.content | b64decode | from_yaml }}" - -- name: Extract the port from the services registry and save it as a persistent fact - ansible.builtin.set_fact: - ioc_port: "{{ services_registry.services | selectattr('name', 'equalto', target_service_name_lower) | map(attribute='ioc_port') | first | default(none) }}" - -- name: Fail if the service or port wasn't found in the registry - ansible.builtin.fail: - msg: "Service '{{ target_service_name_lower }}' not found in services registry or port not set" - when: ioc_port | trim == "" or ioc_port is none - - name: "[{{ target_service_name_lower }}] Establish environment naming conventions" ansible.builtin.set_fact: service_name_upper: "{{ target_service_name_lower | upper }}" diff --git a/ansible/tasks/ioc/ioc-start.yml b/ansible/tasks/ioc/ioc-start.yml index e3ee200..110e40c 100644 --- a/ansible/tasks/ioc/ioc-start.yml +++ b/ansible/tasks/ioc/ioc-start.yml @@ -1,4 +1,7 @@ --- +- name: Clone repo and get/set ioc_port + ansible.builtin.import_tasks: ../utils/get-ioc-port.yml + - name: "[{{ ioc_port }}] Start IOC" ansible.builtin.shell: | sudo shellbox status diff --git a/ansible/tasks/utils/get-ioc-port.yml b/ansible/tasks/utils/get-ioc-port.yml new file mode 100644 index 0000000..cb4c0ea --- /dev/null +++ b/ansible/tasks/utils/get-ioc-port.yml @@ -0,0 +1,26 @@ +--- +- name: Clone this repository + ansible.builtin.git: + repo: "git@gitea.psi.ch:sls/hla_framework_bd.git" + dest: "{{ workspace_dir }}" + accept_hostkey: true + version: "{{ branch_name }}" + force: true + +- name: Read the service registry file + ansible.builtin.slurp: + src: "{{ workspace_dir }}/config/services_registry.yml" + register: remote_registry_file + +- name: Parse the service registry YAML content into a fact + ansible.builtin.set_fact: + services_registry: "{{ remote_registry_file.content | b64decode | from_yaml }}" + +- name: Extract the port from the services registry and save it as a persistent fact + ansible.builtin.set_fact: + ioc_port: "{{ services_registry.services | selectattr('name', 'equalto', target_service_name_lower) | map(attribute='ioc_port') | first | default(none) }}" + +- name: Fail if the service or port wasn't found in the registry + ansible.builtin.fail: + msg: "Service '{{ target_service_name_lower }}' not found in services registry or port not set" + when: ioc_port | trim == "" or ioc_port is none