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

feat: Update playbook for new supported OS: SUSE, openSUSE #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ informed of the latest Bamboo Firewall updates:
<td>RHEL 9</td>
<td>Verified</td>
</tr>
<tr>
<td rowspan="2">SUSE</td>
<td>SLES 15</td>
<td>Verified</td>
</tr>
<tr>
<td>SLED 15</td>
<td>Verified</td>
</tr>
<tr>
<td rowspan="1">openSUSE</td>
<td>openSUSE Leap 15</td>
<td>Verified</td>
</tr>
<tr>
<td rowspan="3">Debian</td>
<td>Debian 8</td>
Expand Down
42 changes: 26 additions & 16 deletions demo/playbook/inventories/production/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@ docker_compose_ver: "v2.20.2"
# OS compatibility check
#----------------
OS_DISTRIBUTION_VALID:
- "Ubuntu"
- "CentOS"
- "RedHat"
UBUNTU_DISTRIBUTION_VALID:
- "20"
- "22"
- "24"

CENTOS_DISTRIBUTION_VALID:
- "7"
- "8"
- "9"
REDHAT_DISTRIBUTION_VALID:
- "7"
- "8"
- "9"
- name: "Ubuntu"
versions:
- 20
- 22
- 24
- name: "CentOS"
versions:
- 7
- 8
- 9
- name: "RedHat"
versions:
- 7
- 8
- 9
- name: "SUSE"
variants:
- "SLED"
- "SLES"
versions:
- 15
- name: "openSUSE"
variants:
- "openSUSE Leap"
versions:
- 15

#----------------
# Image version
Expand Down
89 changes: 57 additions & 32 deletions demo/playbook/roles/bamboofw_agent/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
---
- name: Debug playbook
debug:
msg: "Perform checking to ensure OS is supported by playbook"

- name: OS checking and playbook decision
block:
- name: Check if OS is matching with these below
ansible.builtin.assert:
that:
- ansible_facts['distribution'] in OS_DISTRIBUTION_VALID
fail_msg: "This playbook requiures the OS to be one of the following {{ OS_DISTRIBUTION_VALID }}"
success_msg: "The opearting system {{ ansible_facts['distribution'] }} is allowed"

- name: Gather facts from remote machine
- name: Define OS
set_fact:
os_names: "{{ OS_DISTRIBUTION_VALID | map(attribute='name') | list }}"
os_variants: "{{ OS_DISTRIBUTION_VALID | selectattr('variants', 'defined') | map(attribute='variants') | flatten | list }}"
find_distribution: >-
{{
(OS_DISTRIBUTION_VALID | selectattr('name', 'equalto', ansible_facts['distribution']) | list) +
(OS_DISTRIBUTION_VALID | selectattr('variants', 'defined') | selectattr('variants', 'contains', ansible_facts['distribution']) | list)
}}
os_major_version: "{{ ansible_facts['distribution_version'].split('.')[0] }}"

- name: End playbook if OS is not supported
meta: end_play
when: ansible_facts['distribution'] not in OS_DISTRIBUTION_VALID
ignore_errors: yes

- name: Include some preparation tasks if distribution is not ubuntu
import_tasks: roles/bamboofw_agent/tasks/pre-tasks.yml
when: ansible_facts['distribution'] != 'Ubuntu'
- name: Check if OS is supported
set_fact:
os_supported: >-
{% if find_distribution | length > 0 %}
{% set os_info = find_distribution[0] %}
{% if os_info.versions is not defined or os_major_version | float in os_info.versions %}
1
{% else %}
0
{% endif %}
{% else %}
-1
{% endif %}

- name: Assert OS is supported
assert:
that: os_supported|int== 1
fail_msg: >-
{% if os_supported|int == 0 %}
The current version {{ ansible_facts['distribution_version'] }} is not supported for {{ ansible_facts['distribution'] }}.
Supported versions for {{ ansible_facts['distribution'] }} are: {{ find_distribution[0].versions }}.
{% else %}
Current operating system {{ ansible_facts['distribution'] }} is not supported.
This playbook requires the OS to be one of the following {{ os_names + os_variants }}.
{% endif %}
success_msg: "The operating system {{ ansible_facts['distribution'] }} version {{ ansible_facts['distribution_version'] }} is allowed."

- name: Default execution for all supported distribution
block:
Expand All @@ -39,9 +53,10 @@
create: true
tags: update_hostname

- name: Set hosts name
hostname:
name: "{{ name }}"
- name: Set hostname
shell: hostnamectl set-hostname '{{ name }}'
args:
warn: false

- name: Build hosts file for etcd
lineinfile:
Expand Down Expand Up @@ -101,13 +116,24 @@
- { file_var: "{{ cert }}", file_name: etcd.pem }
- { file_var: "{{ key }}", file_name: etcd-key.pem }

- name: "Create a calico service"
template:
src: templates/calico.service.j2
dest: /lib/systemd/system/calico-felix.service
owner: root
group: root
mode: 0644
- name: "Ensure systemd directory exists and create a calico service"
block:
- name: Check if systemd directory exists
stat:
path: /lib/systemd/system
register: systemd_dir

- name: Ensure systemd directory is present
command: mkdir -p /lib/systemd/system
when: not systemd_dir.stat.exists

- name: Create a calico service
template:
src: templates/calico.service.j2
dest: /lib/systemd/system/calico-felix.service
owner: root
group: root
mode: 0644

- name: "Set external lib if OS is too old"
shell: sudo patchelf --set-interpreter /usr/local/glibc-2.22/lib/ld-linux-x86-64.so.2 --set-rpath /usr/local/glibc-2.22/lib:/usr/lib64 /usr/local/bin/calico-felix-amd64
Expand All @@ -120,5 +146,4 @@
name: calico-felix
state: restarted
daemon_reload: true
enabled: true

enabled: true