Skip to content

Commit

Permalink
roles/update: add update role
Browse files Browse the repository at this point in the history
This role can be used to update a SEAPATH machine.

It is based on the update_machine_cluster.yaml and
update_machine_standalone.yaml of the main branch.

Signed-off-by: Mathieu Dupré <[email protected]>
  • Loading branch information
dupremathieu committed Dec 6, 2024
1 parent e2c7d9f commit 30ef9cb
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
27 changes: 27 additions & 0 deletions roles/update/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SEAPATH Update Role

This role can be used to update a SEAPATH machine.

⚠ For the moment, only Yocto’s version of SEAPATH is supported.

## Requirements

No requirement.

## Role Variables

| Variable | Required | Default | Comments |
|-------------------------|----------|-----------|--------------------------------------------------|
| swu_image | yes | swu_image | Path of the swupdate file on the Ansible machine |

## Dependencies

No dependency.

## Example Playbook

```yaml
- hosts: cluster_machines
roles:
- { role: seapath_ansible.update }
```
5 changes: 5 additions & 0 deletions roles/update/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0

---
swu_image: update.swu
9 changes: 9 additions & 0 deletions roles/update/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0
---
galaxy_info:
author: "Seapath"
description: Update a SEAPATH machine
min_ansible_version: 2.9.10
license: Apache-2.0
dependencies: []
61 changes: 61 additions & 0 deletions roles/update/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0

---

- name: Check if the system have swupdate
command: swupdate -v
register: swupdate_version
ignore_errors: yes
- fail:
msg: "Only Swupdate update is supported"
when: swupdate_version.rc != 0


- name: Check the SEAPATH mode, cluster or standalone
stat:
path: /etc/corosync/corosync.conf
register: corosync_conf

- block:
- name: Set hypervisor in maintenance mode
command: crm node standby "{{ inventory_hostname }}"
- name: Wait for all ressources to be migrated
shell:
cmd: crm status|grep "Migrating"|wc -l
register: check_migration
until: check_migration.stdout == '0'
retries: 10
when: corosync_conf.stat.exists

- name: Copy SWU file on machine
copy:
src: "{{ swu_image_path }}"
dest: "/tmp/update.swu"
- name: Apply update
command: swupdate -i /tmp/update.swu
- name: Reboot host
reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
- name: Wait systemd has finished to boot
command: systemctl is-system-running --wait
register: system_status
failed_when: system_status.rc != 0 and system_status.rc != 1
tags:
- skip_ansible_lint


- name: unset maintenance mode for hypervisor
command: crm node online "{{ inventory_hostname }}"
when: corosync_conf.stat.exists

- name: Check if update has succeed
shell:
cmd: journalctl -u swupdate_check.service -b |grep "Update have failed"|wc -l
register: update_status
failed_when: update_status.stdout != '0'

0 comments on commit 30ef9cb

Please sign in to comment.