Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor distro detection #645

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion playbooks/cluster_setup_ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- name: Configure HA basics
hosts: cluster_machines
become: true
gather_facts: true
vars:
tmpdir: "/tmp"
corosync_node_list: "{{ groups['cluster_machines'] | list }}"
Expand Down
14 changes: 6 additions & 8 deletions playbooks/seapath_setup_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@
# This playbooks can also configure VMs created with build_debian_iso
# This playbook also configures Yocto standalone machine (no cluster)

- name: Gather ansible_distribution
- name: Detect Seapath distribution
hosts:
- cluster_machines
- standalone_machine
tasks:
- name: Gather only the ansible_distribution fact
ansible.builtin.setup:
filter: ansible_distribution
roles:
- detect_seapath_distro

- import_playbook: seapath_setup_prerequiscentos.yaml
when: ansible_distribution | regex_search("CentOS|RedHat")
when: seapath_distro == "CentOS"
eroussy marked this conversation as resolved.
Show resolved Hide resolved

- import_playbook: seapath_setup_prerequisdebian.yaml
when: ansible_distribution | regex_search("Debian")
when: seapath_distro == "Debian"

- import_playbook: seapath_setup_prerequisyocto.yaml
when: ansible_distribution | regex_search("Yocto")
when: seapath_distro == "Yocto"

- import_playbook: seapath_setup_network.yaml

Expand Down
9 changes: 0 additions & 9 deletions playbooks/seapath_setup_snmp.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Copyright (C) 2024, RTE (http://www.rte-france.com)
# SPDX-License-Identifier: Apache-2.0

- name: Gather ansible_distribution
hosts:
- cluster_machines
- standalone_machine
tasks:
- name: Gather only the ansible_distribution fact
ansible.builtin.setup:
filter: ansible_distribution

- name: Configure snmp
hosts:
- cluster_machines
Expand Down
9 changes: 0 additions & 9 deletions playbooks/seapath_setup_timemaster.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Copyright (C) 2024, RTE (http://www.rte-france.com)
# SPDX-License-Identifier: Apache-2.0

- name: Gather ansible_distribution
hosts:
- cluster_machines
- standalone_machine
tasks:
- name: Gather only the ansible_distribution fact
ansible.builtin.setup:
filter: ansible_distribution

- name: Configure timemaster
hosts:
- cluster_machines
Expand Down
4 changes: 3 additions & 1 deletion playbooks/test_run_cukinia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
- cluster_machines
- standalone_machine
- VMs
roles:
- detect_seapath_distro
tasks:
- include_vars: "../vars/{{ ansible_distribution }}_paths.yml"
- include_vars: "../vars/{{ seapath_distro }}_paths.yml"

- hosts:
- cluster_machines
Expand Down
2 changes: 1 addition & 1 deletion roles/ci_restore_snapshot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This role restores the LVM snapshot of the root LV and re-creates it

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
4 changes: 2 additions & 2 deletions roles/ci_restore_snapshot/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []

dependencies:
- role: detect_seapath_distro
2 changes: 1 addition & 1 deletion roles/ci_restore_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

---
- include_vars: "{{ ansible_distribution | replace(' ', '_') }}.yml"
- include_vars: "{{ seapath_distro }}.yml"

- name: "grub conf"
lineinfile:
Expand Down
2 changes: 1 addition & 1 deletion roles/configure_admin_user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This role copy the root ssh key to admin user's. This user is used by Debian whe

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
3 changes: 2 additions & 1 deletion roles/configure_admin_user/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []
dependencies:
- role: detect_seapath_distro
2 changes: 1 addition & 1 deletion roles/configure_admin_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
state: present
key: "{{ lookup('file','buffer/' + item + '-id_rsa.pub') }}"
with_items: "{{ groups['hypervisors'] }}"
when: ansible_distribution | regex_search("CentOS|Debian")
when: seapath_distro in [ "CentOS", "Debian" ]
2 changes: 1 addition & 1 deletion roles/configure_ha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This role configures the High Availability part of a seapath cluster (Corosync a

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
3 changes: 2 additions & 1 deletion roles/configure_ha/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []
dependencies:
- role: detect_seapath_distro
2 changes: 1 addition & 1 deletion roles/configure_ha/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

---
- include_vars: "{{ ansible_distribution | replace(' ', '_') }}.yml"
- include_vars: "{{ seapath_distro }}.yml"

- name: Save cluster machine informations
template:
Expand Down
25 changes: 25 additions & 0 deletions roles/detect_seapath_distro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Detect Seapath distribution Role

This role detects the Seapath distribution and set the seapath_distro fact.
seapath_distro can have one of the following value:
- Debian
- CentOS
- Yocto

If the role can't detect one of these distro it fails.

## Requirements

No requirement.

## Role Variables

No variables.

## Example Playbook

```yaml
- hosts: cluster_machines
roles:
- { role: seapath_ansible.detect_seapath_distro }
```
19 changes: 19 additions & 0 deletions roles/detect_seapath_distro/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0
---
galaxy_info:
author: "Seapath"
description: Detect the SEAPATH distribution and set seapath_distro fact.
license: Apache-2.0
min_ansible_version: 2.9.10
platforms:
- name: Yocto
versions:
- all
- name: Debian
versions:
- all
- name: CentOS
versions:
- all
dependencies: []
35 changes: 35 additions & 0 deletions roles/detect_seapath_distro/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2024 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0

---
- name: Gather only ansible_distribution facts
ansible.builtin.setup:
filter: ansible_distribution*

- name: Detect Debian distribution
set_fact:
seapath_distro: Debian
when: ansible_distribution | regex_search("Debian")

- name: Detect Centos distribution
set_fact:
seapath_distro: CentOS
when: ansible_distribution | regex_search("CentOS|RedHat")

- name: Detect Yocto distribution
block:
- name: Search CPE_NAME field of {{ ansible_distribution_file_path }}
command: grep 'CPE_NAME.*cpe:/o:openembedded' {{ ansible_distribution_file_path }}
eroussy marked this conversation as resolved.
Show resolved Hide resolved
register: ret
failed_when: ret.rc != 0 and ret.rc != 1
- name: Set seapath_distro for Yocto distro
set_fact:
seapath_distro: Yocto
when: ret.rc == 0
when: seapath_distro is not defined

- name: Check distro detection
fail:
msg: "The Seapath distribution could not be determined"
when: seapath_distro is not defined
...
2 changes: 1 addition & 1 deletion roles/network_configovs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This role configures OVS

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
3 changes: 2 additions & 1 deletion roles/network_configovs/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []
dependencies:
- role: detect_seapath_distro
3 changes: 1 addition & 2 deletions roles/network_configovs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

---
- include_vars: "{{ ansible_distribution | replace(' ', '_') }}.yml"
- include_vars: "{{ seapath_distro }}.yml"

- name: Create OVS configuration
template:
Expand All @@ -29,4 +29,3 @@
when:
- ovs_vsctl_cmds is defined
loop: "{{ ovs_vsctl_cmds }}"

2 changes: 1 addition & 1 deletion roles/snmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This role configure the SNMP feature

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
3 changes: 2 additions & 1 deletion roles/snmp/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []
dependencies:
- role: detect_seapath_distro
2 changes: 1 addition & 1 deletion roles/snmp/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

---
- include_vars: "{{ ansible_distribution | replace(' ', '_') }}.yml"
- include_vars: "{{ seapath_distro }}.yml"

- name: configure snmp
block:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion roles/timemaster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This role configures timemaster

## Requirements

no requirement.
- detect_seapath_distro

## Role Variables

Expand Down
3 changes: 2 additions & 1 deletion roles/timemaster/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ galaxy_info:
- name: Debian
versions:
- all
dependencies: []
dependencies:
- role: detect_seapath_distro
2 changes: 1 addition & 1 deletion roles/timemaster/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

---
- include_vars: "{{ ansible_distribution | replace(' ', '_') }}.yml"
- include_vars: "{{ seapath_distro }}.yml"

- name: Populate service facts
service_facts:
Expand Down
15 changes: 13 additions & 2 deletions src/ceph-ansible-patches/distro_not_supported.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
diff --git a/roles/ceph-validate/meta/main.yml b/roles/ceph-validate/meta/main.yml
index 1c6197efd..339e30deb 100644
--- a/roles/ceph-validate/meta/main.yml
+++ b/roles/ceph-validate/meta/main.yml
@@ -11,4 +11,5 @@ galaxy_info:
- 7
galaxy_tags:
- system
-dependencies: []
+dependencies:
+ - role: ../../roles/detect_seapath_distro
diff --git a/roles/ceph-validate/tasks/check_system.yml b/roles/ceph-validate/tasks/check_system.yml
index dc8cdd6fd..4a9ffff4d 100644
index dc8cdd6fd..8f7d224eb 100644
--- a/roles/ceph-validate/tasks/check_system.yml
+++ b/roles/ceph-validate/tasks/check_system.yml
@@ -22,7 +22,9 @@
Expand All @@ -9,7 +20,7 @@ index dc8cdd6fd..4a9ffff4d 100644
- when: ansible_facts['os_family'] not in ['Debian', 'RedHat', 'ClearLinux', 'Suse']
+ when:
+ - ansible_facts['os_family'] not in ['Debian', 'RedHat', 'ClearLinux', 'Suse']
+ - "'Yocto' not in ansible_distribution"
+ - seapath_distro != "Yocto"

- name: fail on unsupported CentOS release
fail:
17 changes: 14 additions & 3 deletions src/ceph-ansible-patches/osd_no_package.diff
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
diff --git a/roles/ceph-osd/meta/main.yml b/roles/ceph-osd/meta/main.yml
index 3c2a26e89..283bae30b 100644
--- a/roles/ceph-osd/meta/main.yml
+++ b/roles/ceph-osd/meta/main.yml
@@ -11,4 +11,5 @@ galaxy_info:
- 7
galaxy_tags:
- system
-dependencies: []
+dependencies:
+ - role: ../../roles/detect_seapath_distro
diff --git a/roles/ceph-osd/tasks/main.yml b/roles/ceph-osd/tasks/main.yml
index 623731ddd..d9e281f2b 100644
index 623731ddd..e1631dc01 100644
--- a/roles/ceph-osd/tasks/main.yml
+++ b/roles/ceph-osd/tasks/main.yml
@@ -24,6 +24,7 @@
when:
- not containerized_deployment | bool
- ansible_facts['os_family'] != 'ClearLinux'
+ - "'Yocto' not in ansible_distribution"

+ - seapath_distro != "Yocto"
- name: install numactl when needed
package:
Loading