Files
psi.bec/tasks/main.yaml
T
2025-07-22 10:40:42 +02:00

215 lines
5.7 KiB
YAML

---
- name: Install redis
ansible.builtin.dnf:
name: '@redis:6'
state: present
- name: Copy redis config
ansible.builtin.template:
src: redis.conf.j2
dest: /etc/redis.conf
mode: '0644'
notify:
- Enable and (re-)start redis
- name: Install required rpm packages
ansible.builtin.dnf:
name:
- python3.11
- git
- tmux
state: latest
- name: EPICS setup
include_tasks: epics_setup.yaml
- 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://github.com/bec-project/bec.git
dest: "{{ bec_path }}/bec"
version: "{{ bec_version }}"
- name: Clone Ophyd Devices repository
become_user: "{{ bec_user }}"
ansible.builtin.git:
repo: https://github.com/bec-project/ophyd_devices.git
dest: "{{ bec_path }}/ophyd_devices"
version: "{{ ophyd_devices_version }}"
- name: Clone BEC Widgets repository
become_user: "{{ bec_user }}"
ansible.builtin.git:
repo: https://github.com/bec-project/bec_widgets.git
dest: "{{ bec_path }}/bec_widgets"
version: "{{ bec_widgets_version }}"
- name: Create user branches in git repositories
become_user: "{{ bec_user }}"
ansible.builtin.command:
cmd: git switch -c {{ bec_user_branch_name }}
chdir: "{{ bec_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- 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' }}"
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: Create user branches in git repositories of plugins
become_user: "{{ bec_user }}"
ansible.builtin.command:
cmd: git switch -c {{ bec_user_branch_name }}
chdir: "{{ bec_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- 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 bec_ipython_client
become_user: "{{ bec_user }}"
ansible.builtin.pip:
name: "{{ bec_path }}/bec/bec_ipython_client"
editable: true
virtualenv_command: python3.11 -m venv
virtualenv: "{{ bec_venv_path }}"
- 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
- name: Copy BEC service files
ansible.builtin.template:
src: bec-server.service.j2
dest: /etc/systemd/system/bec-server.service
notify:
- (Re-)start BEC server
- name: Copy BEC service scripts
ansible.builtin.template:
src: bec-server.sh.j2
dest: /usr/local/sbin/bec-server.sh
mode: u+x
notify:
- (Re-)start BEC server
- name: Create a link to the current deployment
become_user: "{{ bec_user }}"
ansible.builtin.file:
src: "{{ bec_path }}"
dest: "{{ bec_deployments_path }}/{{ deployment_name }}"
state: link
when: not ansible_check_mode
- name: Copy BEC set account binary
become_user: "{{ bec_user }}"
ansible.builtin.copy:
src: bec_set_account
dest: "{{ bec_path }}/bec/bin/bec_set_account/bec_set_account"
mode: u+x,g=x,o=
- name: Copy BEC set account script
become_user: "{{ bec_user }}"
ansible.builtin.template:
src: bec-set-account.j2
dest: "{{ bec_path }}/bec-set-account"
mode: u+x,g=x,o=
# BEC client-related tasks
- name: Add bec startup script
ansible.builtin.template:
src: bec.j2
dest: /usr/local/bin/bec
mode: '0755'
- name: Install vscode
become: true
ansible.builtin.dnf:
name: code
state: latest
- name: Install vscode extensions
become_user: "{{ bec_user }}"
ansible.builtin.shell:
cmd: code --install-extension {{ item }} --force
loop:
- beamline-experiment-control.bec
- ms-vscode-remote.remote-ssh
- ms-python.python
- ms-python.pylint
register: result
changed_when: result.stdout is not search('is already installed.')