- Update pruning options to include filters for containers, images, networks, and volumes. - Modify handlers to restart Podman resources based on new conditions. - Expand Molecule tests to verify networks, volumes, pods, and containers. - Adjust service management tasks for Podman services and auto-update. - Refactor tasks for better clarity and maintainability.
260 lines
8.5 KiB
YAML
260 lines
8.5 KiB
YAML
---
|
|
- name: Verify debian trixie (quadlet containers)
|
|
hosts: debian-trixie
|
|
gather_facts: true
|
|
tasks:
|
|
- name: Verify quadlet .container file exists on Debian Trixie
|
|
ansible.builtin.stat:
|
|
path: "/etc/containers/systemd/test_container.container"
|
|
register: quadlet_file
|
|
|
|
- name: Assert quadlet file exists on Trixie
|
|
ansible.builtin.assert:
|
|
that:
|
|
- quadlet_file.stat.exists
|
|
fail_msg: "Expected quadlet .container file not found for test_container"
|
|
|
|
- name: Verify test container service is active
|
|
ansible.builtin.systemd_service:
|
|
name: "test_container"
|
|
state: started
|
|
ignore_errors: yes
|
|
|
|
- name: Verify debian bookworm (systemd-service containers)
|
|
hosts: debian-bookworm
|
|
gather_facts: true
|
|
tasks:
|
|
- name: Verify systemd service file exists on Debian Bookworm
|
|
ansible.builtin.stat:
|
|
path: "/etc/systemd/system/container-test_container.service"
|
|
register: systemd_service
|
|
|
|
- name: Assert systemd service exists on Bookworm
|
|
ansible.builtin.assert:
|
|
that:
|
|
- systemd_service.stat.exists
|
|
fail_msg: "Expected systemd service file not found for test_container"
|
|
|
|
- name: Verify test container service is active
|
|
ansible.builtin.systemd_service:
|
|
name: "container-test_container"
|
|
state: started
|
|
ignore_errors: yes
|
|
|
|
- name: Verify Podman networks
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: List all Podman networks
|
|
containers.podman.podman_network_info:
|
|
register: network_info
|
|
become: true
|
|
|
|
- name: Verify test_network exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- network_info.networks | selectattr('name', 'equalto', 'test_network') | list | length > 0
|
|
fail_msg: "Network 'test_network' not found"
|
|
|
|
- name: Verify test_network_custom exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- network_info.networks | selectattr('name', 'equalto', 'test_network_custom') | list | length > 0
|
|
fail_msg: "Network 'test_network_custom' not found"
|
|
|
|
- name: Verify test_network_custom driver type
|
|
ansible.builtin.assert:
|
|
that:
|
|
- (network_info.networks | selectattr('name', 'equalto', 'test_network_custom') | first)['driver'] == 'bridge'
|
|
fail_msg: "test_network_custom driver is not bridge"
|
|
|
|
- name: Verify test_macvlan driver type
|
|
ansible.builtin.assert:
|
|
that:
|
|
- (network_info.networks | selectattr('name', 'equalto', 'test_macvlan') | first)['driver'] == 'macvlan'
|
|
fail_msg: "test_macvlan driver is not macvlan"
|
|
when: (network_info.networks | selectattr('name', 'equalto', 'test_macvlan') | list | length) > 0
|
|
|
|
- name: Verify Podman volumes
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: List all Podman volumes
|
|
containers.podman.podman_volume_info:
|
|
register: volume_info
|
|
become: true
|
|
|
|
- name: Verify test_volume exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- volume_info.volumes | selectattr('Name', 'equalto', 'test_volume') | list | length > 0
|
|
fail_msg: "Volume 'test_volume' not found"
|
|
|
|
- name: Verify test_volume_2 exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- volume_info.volumes | selectattr('Name', 'equalto', 'test_volume_2') | list | length > 0
|
|
fail_msg: "Volume 'test_volume_2' not found"
|
|
|
|
- name: Get volume details
|
|
ansible.builtin.shell:
|
|
cmd: podman volume inspect test_volume
|
|
register: volume_inspect
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Verify volume is properly configured
|
|
ansible.builtin.assert:
|
|
that:
|
|
- '"test_volume" in volume_inspect.stdout'
|
|
fail_msg: "Volume 'test_volume' details not found"
|
|
|
|
- name: Verify Podman pods
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: List all Podman pods
|
|
containers.podman.podman_pod_info:
|
|
register: pod_info
|
|
become: true
|
|
|
|
- name: Verify test_pod exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- pod_info.pods | selectattr('Name', 'equalto', 'test_pod') | list | length > 0
|
|
fail_msg: "Pod 'test_pod' not found"
|
|
|
|
- name: Get pod status
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman pod ls --format='{{.Name}} {{.Status}}'{% endraw %}"
|
|
register: pod_list
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Verify test_pod status
|
|
ansible.builtin.assert:
|
|
that:
|
|
- '"test_pod" in pod_list.stdout'
|
|
fail_msg: "Pod 'test_pod' not in podman pod ls output"
|
|
|
|
- name: Verify pod_container is in test_pod
|
|
ansible.builtin.shell:
|
|
cmd: "podman pod inspect test_pod | grep -o '\"Name\": \"[^\"]*\"' | grep pod_container"
|
|
register: pod_container_check
|
|
become: true
|
|
failed_when: pod_container_check.rc not in [0, 1]
|
|
changed_when: false
|
|
|
|
- name: Assert pod_container is in test_pod
|
|
ansible.builtin.assert:
|
|
that:
|
|
- pod_container_check.rc == 0
|
|
fail_msg: "Container 'pod_container' not found in pod 'test_pod'"
|
|
when: ansible_distribution_major_version | int < 13
|
|
|
|
- name: Verify Podman containers
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: List all Podman containers
|
|
containers.podman.podman_container_info:
|
|
register: container_info
|
|
become: true
|
|
|
|
- name: Verify test_container exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- container_info.containers | selectattr('Name', 'equalto', 'test_container') | list | length > 0
|
|
fail_msg: "Container 'test_container' not found"
|
|
|
|
- name: Verify volume_test_container exists and uses test_volume
|
|
ansible.builtin.assert:
|
|
that:
|
|
- container_info.containers | selectattr('Name', 'equalto', 'volume_test_container') | list | length > 0
|
|
fail_msg: "Container 'volume_test_container' not found"
|
|
|
|
- name: Get volume_test_container mounts
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman inspect volume_test_container --format='{{.Mounts}}'{% endraw %}"
|
|
register: container_mounts
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Verify test_volume is mounted in volume_test_container
|
|
ansible.builtin.assert:
|
|
that:
|
|
- '"test_volume" in container_mounts.stdout'
|
|
fail_msg: "Volume 'test_volume' not mounted in container 'volume_test_container'"
|
|
|
|
- name: Verify common checks across all systems
|
|
hosts: all
|
|
gather_facts: true
|
|
tasks:
|
|
- name: Verify nginx responds on localhost
|
|
ansible.builtin.uri:
|
|
url: http://127.0.0.1:8080
|
|
register: nginx_get_uri
|
|
failed_when:
|
|
- nginx_get_uri.msg is not match("OK")
|
|
- nginx_get_uri.content_length | int <= 0
|
|
- nginx_get_uri.failed
|
|
- nginx_get_uri.status != 200
|
|
|
|
- name: Verify Podman package is installed
|
|
ansible.builtin.package_facts:
|
|
manager: auto
|
|
|
|
- name: Assert Podman is installed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "'podman' in ansible_facts.packages"
|
|
fail_msg: "Podman package is not installed"
|
|
|
|
- name: Verify Podman daemon is available
|
|
ansible.builtin.shell:
|
|
cmd: podman --version
|
|
register: podman_version
|
|
changed_when: false
|
|
|
|
- name: Print Podman version
|
|
ansible.builtin.debug:
|
|
msg: "Podman version: {{ podman_version.stdout }}"
|
|
|
|
- name: Get total container count
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman ps -a --format='{{.Names}}' | wc -l{% endraw %}"
|
|
register: container_count
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Get total network count
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman network ls --format='{{.Name}}' | tail -n +2 | wc -l{% endraw %}"
|
|
register: network_count
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Get total volume count
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman volume ls --format='{{.Name}}' | tail -n +2 | wc -l{% endraw %}"
|
|
register: volume_count
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Get total pod count
|
|
ansible.builtin.shell:
|
|
cmd: "{% raw %}podman pod ls --format='{{.Name}}' | tail -n +2 | wc -l{% endraw %}"
|
|
register: pod_count
|
|
become: true
|
|
changed_when: false
|
|
|
|
- name: Print resource summary
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
Podman Resource Summary:
|
|
- Total Containers: {{ container_count.stdout | trim }}
|
|
- Total Networks: {{ network_count.stdout | trim }}
|
|
- Total Volumes: {{ volume_count.stdout | trim }}
|
|
- Total Pods: {{ pod_count.stdout | trim }}
|
|
|