diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..ae4b8c4 --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,8 @@ +--- +bec_user: bec +bec_path: /opt/bec_deployment + +bec_version: main +ophyd_devices_version: main +bec_widgets_version: main +bec_plugins: {} diff --git a/handlers/main.yaml b/handlers/main.yaml new file mode 100644 index 0000000..89119fd --- /dev/null +++ b/handlers/main.yaml @@ -0,0 +1,9 @@ +--- +- name: (Re-)start BEC server + become_user: "{{ bec_user }}" + ansible.builtin.shell: + cmd: | + source {{ bec_venv_path }}/bin/activate + bec-server start + chdir: "{{ bec_path }}" + when: not ansible_check_mode diff --git a/meta/main.yaml b/meta/main.yaml new file mode 100644 index 0000000..fdd7b31 --- /dev/null +++ b/meta/main.yaml @@ -0,0 +1,8 @@ +galaxy_info: + author: BEC developers + description: Installation and configuration of BEC + company: Paul Scherrer Institute + license: MIT + min_ansible_version: 2.9 + galaxy_tags: [] +dependencies: [] diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..a51d615 --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,150 @@ +--- +- name: Install and configure redis + include_role: + name: geerlingguy.redis + vars: + redis_bind_interface: 0.0.0.0 + when: not ansible_check_mode + +- name: Install required rpm packages + ansible.builtin.dnf: + name: + - python3.11 + - git + - tmux + state: present + +- name: Download epics_contexts.yml + ansible.builtin.uri: + url: https://git.psi.ch/gfa_rpms/gfa-global-profile/-/raw/master/src/etc/epics_contexts.yml + dest: /etc + +- name: Download gfa_12_epics.sh + ansible.builtin.uri: + url: https://git.psi.ch/gfa_rpms/gfa-global-profile/-/raw/master/src/etc/profile.d/gfa_12_epics.sh + dest: /etc/profile.d + +- name: Create a folder for BEC deployment + become_user: "{{ bec_user }}" + ansible.builtin.file: + path: "{{ bec_path }}" + state: directory + +- name: Clone BEC repository + become_user: "{{ bec_user }}" + ansible.builtin.git: + repo: https://gitlab.psi.ch/bec/bec.git + dest: "{{ bec_path }}/bec" + version: "{{ bec_version }}" + force: true + +- name: Clone Ophyd Devices repository + become_user: "{{ bec_user }}" + ansible.builtin.git: + repo: https://gitlab.psi.ch/bec/ophyd_devices.git + dest: "{{ bec_path }}/ophyd_devices" + version: "{{ ophyd_devices_version }}" + force: true + +- name: Clone BEC Widgets repository + become_user: "{{ bec_user }}" + ansible.builtin.git: + repo: https://gitlab.psi.ch/bec/bec_widgets.git + dest: "{{ bec_path }}/bec_widgets" + version: "{{ bec_widgets_version }}" + force: true + +- name: Clone BEC plugins + become_user: "{{ bec_user }}" + ansible.builtin.git: + repo: https://oauth2:{{ lookup('env', 'BEC_PLUGIN_TOKEN') }}@gitlab.psi.ch/bec/{{ item.key }}.git + dest: "{{ bec_path }}/{{ item.key }}" + version: "{{ item.value or 'main' }}" + force: true + loop: "{{ bec_plugins | dict2items }}" + when: not ansible_check_mode + +- name: Clear token from git remote url in BEC plugins + become_user: "{{ bec_user }}" + ansible.builtin.command: + cmd: git remote set-url origin https://gitlab.psi.ch/bec/{{ item.key }}.git + chdir: "{{ bec_path }}/{{ item.key }}" + loop: "{{ bec_plugins | dict2items }}" + when: not ansible_check_mode + +- name: Check if venv exists + ansible.builtin.stat: + path: "{{ bec_venv_path }}" + register: bec_venv_path_stat + +- name: Stop bec_server + when: bec_venv_path_stat.stat.exists and bec_venv_path_stat.stat.isdir + become_user: "{{ bec_user }}" + ansible.builtin.shell: + cmd: | + source {{ bec_venv_path }}/bin/activate + bec-server stop + +- name: Delete old venv (if it exists) + become_user: "{{ bec_user }}" + ansible.builtin.file: + path: "{{ bec_venv_path }}" + state: absent + diff: false + +- name: Install bec_lib + become_user: "{{ bec_user }}" + ansible.builtin.pip: + name: "{{ bec_path }}/bec/bec_lib" + editable: true + virtualenv_command: python3.11 -m venv + virtualenv: "{{ bec_venv_path }}" + notify: + - (Re-)start BEC server + +- name: Install ophyd_devices + become_user: "{{ bec_user }}" + ansible.builtin.pip: + name: "{{ bec_path }}/ophyd_devices" + editable: true + virtualenv_command: python3.11 -m venv + virtualenv: "{{ bec_venv_path }}" + notify: + - (Re-)start BEC server + +- name: Install bec_widgets + become_user: "{{ bec_user }}" + ansible.builtin.pip: + name: "{{ bec_path }}/bec_widgets[pyside6]" + editable: true + virtualenv_command: python3.11 -m venv + virtualenv: "{{ bec_venv_path }}" + +- name: Install bec_server + become_user: "{{ bec_user }}" + ansible.builtin.pip: + name: "{{ bec_path }}/bec/bec_server" + editable: true + virtualenv_command: python3.11 -m venv + virtualenv: "{{ bec_venv_path }}" + notify: + - (Re-)start BEC server + +- name: Install BEC plugins + become_user: "{{ bec_user }}" + ansible.builtin.pip: + name: "{{ bec_path }}/{{ item.key }}" + editable: true + virtualenv_command: python3.11 -m venv + virtualenv: "{{ bec_venv_path }}" + loop: "{{ bec_plugins | dict2items }}" + notify: + - (Re-)start BEC server + +- name: Copy BEC service config + become_user: "{{ bec_user }}" + ansible.builtin.template: + src: bec_config.yaml.j2 + dest: "{{ bec_path }}/bec_config.yaml" + notify: + - (Re-)start BEC server diff --git a/templates/bec_config.yaml.j2 b/templates/bec_config.yaml.j2 new file mode 100644 index 0000000..77de5c0 --- /dev/null +++ b/templates/bec_config.yaml.j2 @@ -0,0 +1,17 @@ +redis: + host: localhost + port: 6379 +mongodb: + host: localhost + port: 27017 +scibec: + host: http://localhost + port: 3030 + beamline: MyBeamline + env_file: {{ bec_path }} +service_config: + file_writer: + plugin: default_NeXus_format + base_path: ./ + scilog: + env_file: ./ diff --git a/vars/main.yaml b/vars/main.yaml new file mode 100644 index 0000000..5b94e9b --- /dev/null +++ b/vars/main.yaml @@ -0,0 +1,2 @@ +--- +bec_venv_path: "{{ bec_path }}/bec_venv"