forked from cps-deployments/psi.bec
371 lines
11 KiB
YAML
371 lines
11 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: Get info about deployment path
|
|
ansible.builtin.stat:
|
|
path: "{{ deployment_path }}"
|
|
register: deployment_path_info
|
|
|
|
- name: Remove the old-style symlink if it exists
|
|
become_user: "{{ deployment_user }}"
|
|
ansible.builtin.file:
|
|
path: "{{ deployment_path }}"
|
|
state: absent
|
|
when: deployment_path_info.stat.islnk is defined and deployment_path_info.stat.islnk
|
|
|
|
- name: Create a folder for old deployments
|
|
become_user: "{{ deployment_user }}"
|
|
ansible.builtin.file:
|
|
path: "{{ old_deployments_path }}"
|
|
state: directory
|
|
|
|
- name: Stop bec-server if it exists and running
|
|
ansible.builtin.systemd:
|
|
name: bec-server.service
|
|
state: stopped
|
|
register: systemd_stop_result
|
|
failed_when: "systemd_stop_result is failed and 'Could not find the requested service' not in systemd_stop_result.msg"
|
|
|
|
- name: Move the previous deployment into an old deployments timestamped folder
|
|
ansible.builtin.command:
|
|
cmd: mv {{ deployment_path }} {{ old_deployments_path }}/{{ ansible_date_time['iso8601_basic_short'] }}
|
|
when: deployment_path_info.stat.exists and deployment_path_info.stat.isdir
|
|
|
|
- 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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:{{ bec_bl_push_pat }}@gitea.psi.ch/bec/{{ item.key }}.git
|
|
dest: "{{ deployment_path }}/{{ item.key }}"
|
|
version: "{{ item.value or 'main' }}"
|
|
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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: "{{ 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: Copy BEC set account binary
|
|
become_user: "{{ deployment_user }}"
|
|
ansible.builtin.copy:
|
|
src: bec_set_account
|
|
dest: "{{ 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: "{{ 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"
|