Files
psi.bec/tasks/main.yaml
T
2025-09-22 13:01:27 +02:00

357 lines
10 KiB
YAML

---
- name: Edit redis config on rhel9
ansible.builtin.lineinfile:
path: /etc/redis/redis.conf
regexp: "^bind "
line: bind * -::*
when: ansible_distribution_major_version == "9"
notify:
- Restart redis
- name: Disable redis protected-mode on rhel9
ansible.builtin.lineinfile:
path: /etc/redis/redis.conf
regexp: "^protected-mode "
line: protected-mode no
when: ansible_distribution_major_version == "9"
notify:
- Restart redis
- name: Edit redis config on rhel8
ansible.builtin.lineinfile:
path: /etc/redis.conf
regexp: "^bind "
line: bind 0.0.0.0
when: ansible_distribution_major_version == "8"
notify:
- Restart redis
- name: EPICS setup
include_tasks: epics_setup.yaml
- name: Create a folder for BEC server logs
ansible.builtin.file:
owner: "{{ service_user }}"
path: "/var/log/bec"
state: directory
- name: Create a folder for BEC deployment
become_user: "{{ deployment_user }}"
ansible.builtin.file:
path: "{{ timestamped_deployment_path }}"
state: directory
- name: Create a folder for secrets
ansible.builtin.file:
owner: "{{ service_user }}"
path: "/etc/bec/secrets"
state: directory
mode: "0750"
- name: Get BEC Atlas authentication token
ansible.builtin.uri:
url: "https://bec-atlas-qa.psi.ch/api/v1/user/login"
method: POST
body_format: json
body:
username: "admin@bec_atlas.ch"
password: "{{ bec_atlas_token }}"
return_content: yes
register: atlas_auth_response
when: bec_atlas_token is defined
ignore_errors: true
no_log: true
- name: Fetch deployment credentials from BEC Atlas
ansible.builtin.uri:
url: "https://bec-atlas-qa.psi.ch/api/v1/deploymentCredentials/env?deployment_name={{ ansible_fqdn }}"
method: GET
headers:
Authorization: "Bearer {{ atlas_auth_response['content'] | trim | regex_replace('^\"(.*)\"$', '\\1') }}"
accept: "text/plain"
return_content: yes
register: atlas_credentials
when:
- bec_atlas_token is defined and atlas_auth_response is succeeded
ignore_errors: true
no_log: true
- name: Save BEC Atlas credentials to file
ansible.builtin.copy:
content: "{{ atlas_credentials['content'] }}"
dest: "/etc/bec/secrets/.atlas.env"
mode: "0600"
become_user: "{{ service_user }}"
when: bec_atlas_token is defined and atlas_credentials is succeeded
ignore_errors: true
no_log: true
- name: Clone BEC repository
become_user: "{{ deployment_user }}"
ansible.builtin.git:
repo: https://github.com/bec-project/bec.git
dest: "{{ timestamped_deployment_path }}/bec"
version: "{{ bec_version }}"
- name: Clone Ophyd Devices repository
become_user: "{{ deployment_user }}"
ansible.builtin.git:
repo: https://github.com/bec-project/ophyd_devices.git
dest: "{{ timestamped_deployment_path }}/ophyd_devices"
version: "{{ ophyd_devices_version }}"
- name: Clone BEC Widgets repository
become_user: "{{ deployment_user }}"
ansible.builtin.git:
repo: https://github.com/bec-project/bec_widgets.git
dest: "{{ timestamped_deployment_path }}/bec_widgets"
version: "{{ bec_widgets_version }}"
- name: Create user branches in git repositories
become_user: "{{ deployment_user }}"
ansible.builtin.command:
cmd: git switch -c {{ user_git_branch_name }}
chdir: "{{ timestamped_deployment_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- name: Set user.name in git repositories
become_user: "{{ deployment_user }}"
community.general.git_config:
name: user.name
value: "{{ git_username }}"
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- name: Set user.email in git repositories
become_user: "{{ deployment_user }}"
community.general.git_config:
name: user.email
value: "{{ git_username }}@psi.ch"
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- name: Set pull.rebase in git repositories
become_user: "{{ deployment_user }}"
community.general.git_config:
name: pull.rebase
value: true
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- name: Set core.sharedRepository in git repositories
become_user: "{{ deployment_user }}"
community.general.git_config:
name: core.sharedRepository
value: group
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item }}"
loop:
- bec
- ophyd_devices
- bec_widgets
when: not ansible_check_mode
- name: Clone BEC plugins
become_user: "{{ deployment_user }}"
ansible.builtin.git:
repo: https://git:{{ lookup('env', 'BEC_PLUGIN_TOKEN') }}@gitea.psi.ch/bec/{{ item.key }}.git
dest: "{{ timestamped_deployment_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: "{{ deployment_user }}"
ansible.builtin.command:
cmd: git remote set-url origin https://gitea.psi.ch/bec/{{ item.key }}.git
chdir: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Create user branches in git repositories of plugins
become_user: "{{ deployment_user }}"
ansible.builtin.command:
cmd: git switch -c {{ user_git_branch_name }}
chdir: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Set user.name in git repositories of plugins
become_user: "{{ deployment_user }}"
community.general.git_config:
name: user.name
value: "{{ git_username }}"
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Set user.email in git repositories of plugins
become_user: "{{ deployment_user }}"
community.general.git_config:
name: user.email
value: "{{ git_username }}@psi.ch"
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Set pull.rebase in git repositories of plugins
become_user: "{{ deployment_user }}"
community.general.git_config:
name: pull.rebase
value: true
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Set core.sharedRepository in git repositories of plugins
become_user: "{{ deployment_user }}"
community.general.git_config:
name: core.sharedRepository
value: group
scope: local
repo: "{{ timestamped_deployment_path }}/{{ item.key }}"
loop: "{{ bec_plugins | dict2items }}"
when: not ansible_check_mode
- name: Install bec_lib
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/bec/bec_lib"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
notify:
- (Re-)start BEC server
- name: Install bec_ipython_client
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/bec/bec_ipython_client"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
- name: Install ophyd_devices
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/ophyd_devices"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
notify:
- (Re-)start BEC server
- name: Install bec_widgets
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/bec_widgets[pyside6]"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
- name: Install bec_server
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/bec/bec_server"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
notify:
- (Re-)start BEC server
- name: Install BEC plugins
become_user: "{{ deployment_user }}"
ansible.builtin.pip:
name: "{{ timestamped_deployment_path }}/{{ item.key }}"
editable: true
virtualenv_command: "{{ python_version }} -m venv"
virtualenv: "{{ bec_venv_path }}"
loop: "{{ bec_plugins | dict2items }}"
notify:
- (Re-)start BEC server
- name: Create BEC deployment config directory
become_user: "{{ deployment_user }}"
ansible.builtin.file:
path: "{{ timestamped_deployment_path }}/deployment_configs"
state: directory
- name: Copy BEC service config
become_user: "{{ deployment_user }}"
ansible.builtin.template:
src: bec_config_server.yaml.j2
dest: "{{ timestamped_deployment_path }}/deployment_configs/server.yaml"
notify:
- (Re-)start BEC server
- name: Copy BEC client config
become_user: "{{ deployment_user }}"
ansible.builtin.template:
src: bec_config_client.yaml.j2
dest: "{{ timestamped_deployment_path }}/deployment_configs/client.yaml"
- 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: "{{ deployment_user }}"
ansible.builtin.file:
src: "{{ timestamped_deployment_path }}"
dest: "{{ deployment_path_prefix }}/{{ deployment_name }}"
state: link
when: not ansible_check_mode
- name: Copy BEC set account binary
become_user: "{{ deployment_user }}"
ansible.builtin.copy:
src: bec_set_account
dest: "{{ timestamped_deployment_path }}/bin/"
mode: u+x,g+x
- name: Copy BEC set account script
become_user: "{{ deployment_user }}"
ansible.builtin.template:
src: bec-set-account.j2
dest: "{{ timestamped_deployment_path }}/bec-set-account"
mode: u+x,g+rx
- name: Add bec startup script
ansible.builtin.template:
src: bec.j2
dest: /usr/local/bin/bec
mode: "0755"