Skip to content
Snippets Groups Projects
Commit 8210f37e authored by Thomas Michelat's avatar Thomas Michelat
Browse files

Ansible playbook for online deployment

parent 0c97bfe5
No related branches found
No related tags found
1 merge request!1025Ansible playbook for online deployment
# Automated deployment
Ansible playbook for automated deployment on the online cluster
## Setup Ansible
```bash
$ git clone https://github.com/ansible/ansible.git
$ cd ansible
$ git checkout v2.8.1
```
## Activate the environment
```bash
$ source ansible/hacking/env-setup
```
Alternatively you can use the provided environment on `exflgateway`
```bash
$ source /opt/karabo/ansible/hacking/env-setup
```
## Python dependencies
Ensure `yaml` and `jinja2` packages are installed in your Python environment. If not:
```bash
pip install pyYaml jinja2
```
## Install pycalibration
```bash
./install.yml GROUP_NAME
```
[defaults]
forks = 30
inventory = ./hosts
stdout_callback = debug
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=1200
\ No newline at end of file
---
ansible_user: "xcal"
install_dir: "/scratch/xcal"
pycal_dir: "{{ install_dir }}/pycalibration"
pycal_version: "3.14.3"
[HED]
sa2-onc-0[1:6]
sa2-onc-hed
\ No newline at end of file
#!play
- hosts: all
tasks:
- name: Find all backup directory
find:
paths: "{{ install_dir }}"
patterns: "^pycalibration_backup_\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$"
file_type: directory
use_regex: True
register: backup_dirs
- name: Display matching directories
debug:
msg: "Matching directories: {{ backup_dirs.files | map(attribute='path') | list }}"
- name: Sort backup directories
set_fact:
sorted_backup_dirs: "{{ backup_dirs.files | sort(attribute='mtime', reverse=true) | list }}"
- name: Delete all but the most recent backup
file:
path: "{{ item.path }}"
state: absent
loop: "{{ sorted_backup_dirs[1:] }}"
when: sorted_backup_dirs | length > 1
register: deleted_dirs
- name: Information about backup retention
debug:
msg: |
Kept directory: {{ sorted_backup_dirs[0].path if sorted_backup_dirs else 'None' }}
Deleted directories ({{ deleted_dirs.results | length }}):
{% for dir in deleted_dirs.results %}
- {{ dir.path }}
{% endfor %}
- name: Get current date
command: date +%Y-%m-%dT%H:%M:%S
register: current_date
changed_when: false
- name: Set backup directory name
set_fact:
backup_dir_name: "pycalibration_backup_{{ current_date.stdout }}"
- name: Create backup directory
file:
state: directory
path: "{{ install_dir }}/{{ backup_dir_name }}"
mode: 0755
register: backup_dir
- name: Check for previous installation
stat:
path: "{{ pycal_dir }}"
register: pycal_dir_stat
- name: Backup previous installation
command: "mv {{ pycal_dir }} {{ backup_dir.path }}"
when: pycal_dir_stat.stat.exists
- name: Clone pycalibration
shell: git clone ssh://git@git.xfel.eu:10022/calibration/pycalibration.git -b {{ pycal_version }} {{ pycal_dir }}
- name: create venv
shell: /gpfs/exfel/sw/calsoft/.pyenv/versions/3.8.18/bin/python3 -m venv --prompt pycal-{{ pycal_version }} {{ pycal_dir }}/.venv
- name: Install Pycalibration
shell: all_proxy="http://exflproxy01.desy.de:3128" {{ pycal_dir }}/.venv/bin/pip install -e {{ pycal_dir }}
#!/bin/bash
if [[ $# -lt 2 ]]
then
echo "USAGE: $1 GROUP_NAME"
exit 1
fi
PLAYBOOK="$1"
shift
exec ansible-playbook "$PLAYBOOK" -l "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment