-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from SquirrelCorporation/test-add-upgrade-mol…
…ecule-test [TEST] Refactor package upgrade logic and add Molecule tests
- Loading branch information
Showing
10 changed files
with
154 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ansible/00000000-0000-0000-0000-000000000000/device/roles/upgrade_host_package/debian.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
# tasks/debian.yml | ||
|
||
- name: Perform a dist-upgrade. | ||
ansible.builtin.package: | ||
name: "*" | ||
state: latest | ||
|
||
- name: Check if a reboot is required. | ||
ansible.builtin.stat: | ||
path: /var/run/reboot-required | ||
get_checksum: no | ||
register: reboot_required_file | ||
|
||
- name: Reboot the server if required. | ||
ansible.builtin.reboot: | ||
when: reboot_required_file.stat.exists | ||
|
||
- name: Remove dependencies that are no longer required. | ||
ansible.builtin.package: | ||
autoremove: true |
8 changes: 8 additions & 0 deletions
8
...c/ansible/00000000-0000-0000-0000-000000000000/device/roles/upgrade_host_package/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# tasks/main.yml | ||
|
||
- include_tasks: debian.yml | ||
when: ansible_distribution in ["Debian", "Ubuntu"] | ||
|
||
- include_tasks: rhel.yml | ||
when: ansible_distribution in ["CentOS", "RedHat"] |
21 changes: 21 additions & 0 deletions
21
...c/ansible/00000000-0000-0000-0000-000000000000/device/roles/upgrade_host_package/rhel.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
# tasks/rhel.yml | ||
|
||
- name: Perform a dist-upgrade. | ||
ansible.builtin.package: | ||
name: "*" | ||
state: latest | ||
|
||
- name: Check if a reboot is required. | ||
ansible.builtin.command: /usr/bin/needs-restarting -r | ||
register: needs_restarting | ||
failed_when: needs_restarting.rc not in [0,1,123] | ||
changed_when: needs_restarting.rc == 1 | ||
|
||
- name: Reboot the server if required. | ||
ansible.builtin.reboot: | ||
when: needs_restarting.rc == 1 | ||
|
||
- name: Remove dependencies that are no longer required. | ||
ansible.builtin.package: | ||
autoremove: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Dockerfile.j2 | ||
|
||
FROM {{ item.image }} | ||
|
||
# For Debian-based systems | ||
{% if item.image.startswith('debian') or item.image.startswith('ubuntu') %} | ||
RUN apt-get update && \ | ||
apt-get install -y python3 python3-pip sshpass sudo | ||
{% endif %} | ||
|
||
# For RHEL-based systems | ||
{% if item.image.startswith('centos') or item.image.startswith('rhel') or item.image.startswith('rockylinux') %} | ||
RUN yum update -y && \ | ||
yum install -y python3 python3-pip sshpass sudo | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: true | ||
gather_facts: false | ||
|
||
- import_playbook: "../../../ansible/00000000-0000-0000-0000-000000000000/device/_upgrade.yml" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
|
||
driver: | ||
name: docker | ||
|
||
platforms: | ||
- name: debian-latest | ||
image: debian:latest | ||
command: "sleep infinity" # Keep container running for Molecule to work with | ||
- name: rockylinux | ||
image: rockylinux:9.3 | ||
command: "sleep infinity" # Keep container running for Molecule to work with | ||
|
||
provisioner: | ||
name: ansible | ||
log: true | ||
|
||
scenario: | ||
test_sequence: | ||
- dependency | ||
- destroy | ||
- create | ||
- prepare | ||
- converge | ||
- verify | ||
- destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
collections: | ||
- name: community.docker | ||
version: ">=3.10.2" | ||
- name: community.general | ||
version: ">=7.0.0" | ||
source: https://galaxy.ansible.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
- name: Verify | ||
hosts: all | ||
tasks: | ||
- name: Ensure no packages are pending for upgrade (Debian-based) | ||
ansible.builtin.command: apt list --upgradable | ||
register: apt_upgrade_check | ||
changed_when: false | ||
failed_when: "apt_upgrade_check.stdout | trim != '' and not apt_upgrade_check.stdout is search('Listing...')" | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Ensure no packages are pending for upgrade (RHEL-based) | ||
ansible.builtin.command: yum check-update | ||
register: yum_upgrade_check | ||
changed_when: false | ||
failed_when: > | ||
yum_upgrade_check.stdout is search('^([a-zA-Z0-9_.+-]+)\s+([0-9][a-zA-Z0-9_:\-\.\+~]*)[^\r\n]*') | ||
and not (yum_upgrade_check.stdout | trim is search('Last metadata expiration')) | ||
when: ansible_os_family == "RedHat" | ||
|
||
- name: Debug the result (Debian-based) | ||
ansible.builtin.debug: | ||
msg: "APT check output: {{ apt_upgrade_check.stdout }}" | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Debug the result (RHEL-based) | ||
ansible.builtin.debug: | ||
msg: "YUM check output: {{ yum_upgrade_check.stdout }}" | ||
when: ansible_os_family == "RedHat" |