--- # Copyright 2019 Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - name: Create all containers from /tmp/container-configs become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: '*.json' tripleo_container_manage_systemd_order: true tripleo_container_manage_valid_exit_code: [0] tasks: - include_role: name: tripleo-container-manage post_tasks: - name: Verify that Fedora container was created correctly when: - not ansible_check_mode|bool block: - name: Check for fedora container command: podman container exists fedora - name: Gather facts about fedora container podman_container_info: name: fedora register: fedora_infos - name: Assert that fedora container has the right image assert: that: - "'fedora:latest' in fedora_infos.containers.0.ImageName" fail_msg: 'fedora container has wrong image' success_msg: 'fedora container has the right image' - name: Check if tripleo_fedora systemd service is active command: systemctl is-active --quiet tripleo_fedora register: tripleo_fedora_active_result - name: Assert that tripleo_fedora systemd service is active assert: that: - tripleo_fedora_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd service is not active' success_msg: 'tripleo_fedora systemd service is active' - name: Check if tripleo_fedora systemd healthcheck service is active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result - name: Assert that tripleo_fedora systemd healthcheck service is active assert: that: - tripleo_fedora_healthcheck_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd healthcheck service is not active' success_msg: 'tripleo_fedora systemd healthcheck service is active' - name: Check if tripleo_fedora_bis has systemd service stat: path: /etc/systemd/system/tripleo_fedora_bis.service register: stat_tripleo_fedora_bis_systemd - name: Check if tripleo_fedora_bis has systemd healthcheck timer stat: path: /etc/systemd/system/tripleo_fedora_bis_healthcheck.timer register: stat_tripleo_fedora_bis_systemd_timer - name: Assert that tripleo_fedora_bis has no systemd integration assert: that: - not stat_tripleo_fedora_bis_systemd.stat.exists - not stat_tripleo_fedora_bis_systemd_timer.stat.exists fail_msg: 'tripleo_fedora_bis has systemd service' success_msg: 'tripleo_fedora_bis has no systemd service' - name: Verify that Fedora bis container was created correctly block: - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Gather facts about fedora_bis container podman_container_info: name: fedora_bis register: fedora_bis_infos - name: Assert that fedora_bis container has the right image assert: that: - "'fedora:latest' in fedora_bis_infos.containers.0.ImageName" fail_msg: 'fedora_bis container has wrong image' success_msg: 'fedora_bis container has the right image' - name: Verify that Fedora three container was created correctly block: - name: Check for fedora_three container command: podman container exists fedora_three - name: Gather facts about fedora_three container podman_container_info: name: fedora_three register: fedora_three_infos - name: Assert that fedora_three container has the right image assert: that: - "'fedora:latest' in fedora_three_infos.containers.0.ImageName" fail_msg: 'fedora_three container has wrong image' success_msg: 'fedora_three container has the right image' - name: Test systemd healthcheck dependency on service become: true hosts: all gather_facts: false tasks: - name: Stop systemd service for tripleo_fedora systemd: name: tripleo_fedora.service state: stopped enabled: true - name: Check if tripleo_fedora_healthcheck timer is active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result failed_when: false when: - not ansible_check_mode|bool - name: Assert that tripleo_fedora_healthcheck timer service is not active assert: that: - tripleo_fedora_healthcheck_active_result.rc == 3 fail_msg: 'tripleo_fedora systemd service is active' success_msg: 'tripleo_fedora systemd service is not active' when: - not ansible_check_mode|bool - name: Start systemd service for tripleo_fedora systemd: name: tripleo_fedora.service state: started enabled: true - name: Check if tripleo_fedora_healthcheck timer is active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result until: tripleo_fedora_healthcheck_active_result.rc == 0 retries: 5 delay: 5 when: - not ansible_check_mode|bool - name: Assert that tripleo_fedora_healthcheck timer service is active assert: that: - tripleo_fedora_healthcheck_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd service is not active' success_msg: 'tripleo_fedora systemd service is active' when: - not ansible_check_mode|bool - name: Test idempotency on fedora container become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: '*.json' tripleo_container_manage_systemd_order: true tasks: - name: Gather facts about fedora container before new run podman_container_info: name: fedora register: fedora_infos_old when: - not ansible_check_mode|bool - include_role: name: tripleo-container-manage - name: Gather facts about fedora container after new run podman_container_info: name: fedora register: fedora_infos_new when: - not ansible_check_mode|bool post_tasks: - name: Assert that fedora container has not been re-created assert: that: - fedora_infos_new['containers'][0]['Id'] == fedora_infos_old['containers'][0]['Id'] fail_msg: 'fedora container was wrongly re-created' success_msg: 'fedora container was not re-created' when: - not ansible_check_mode|bool - name: Test systemd state on fedora container after a manual stop become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: '*.json' tripleo_container_manage_systemd_order: true tasks: - name: Stop systemd service for tripleo_fedora in a manual stop systemd: name: tripleo_fedora.service state: stopped enabled: false daemon_reload: true - name: Stop systemd timer for tripleo_fedora in a manual stop systemd: name: tripleo_fedora_healthcheck.timer state: stopped enabled: false daemon_reload: true - include_role: name: tripleo-container-manage post_tasks: - name: Check if tripleo_fedora systemd service is active after a manual stop command: systemctl is-active --quiet tripleo_fedora register: tripleo_fedora_active_result - name: Assert that tripleo_fedora systemd service is active after a manual stop when: - not ansible_check_mode|bool assert: that: - tripleo_fedora_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd service is not active after a manual stop' success_msg: 'tripleo_fedora systemd service is active after a manual stop' - name: Check if tripleo_fedora systemd timer is active after a manual stop command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_timer_active_result - name: Assert that tripleo_fedora systemd timer is active after a manual stop when: - not ansible_check_mode|bool assert: that: - tripleo_fedora_timer_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd timer is not active after a manual stop' success_msg: 'tripleo_fedora systemd timer is active after a manual stop' - name: Manage only one container become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: 'fedora.json' tripleo_container_manage_clean_orphans: false tripleo_container_manage_config_overrides: fedora: image: fedora:rawhide tasks: - include_role: name: tripleo-container-manage post_tasks: - name: Verify that all containers still exist when: - not ansible_check_mode|bool block: - name: Check for fedora container command: podman container exists fedora - name: Gather facts about fedora container podman_container_info: name: fedora register: fedora_infos - name: Assert that fedora container has the right image assert: that: - "'fedora:rawhide' in fedora_infos.containers.0.ImageName" fail_msg: 'fedora container has wrong image' success_msg: 'fedora container has the right image' - name: Check if tripleo_fedora systemd service is active command: systemctl is-active --quiet tripleo_fedora register: tripleo_fedora_active_result - name: Assert that tripleo_fedora systemd service is active assert: that: - tripleo_fedora_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd service is not active' success_msg: 'tripleo_fedora systemd service is active' - name: Check if tripleo_fedora systemd healthcheck service is active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result - name: Assert that tripleo_fedora systemd healthcheck service is active assert: that: - tripleo_fedora_healthcheck_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd healthcheck service is not active' success_msg: 'tripleo_fedora systemd healthcheck service is active' - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Check for fedora_three container command: podman container exists fedora_three - name: Manage a wrong container (user error) become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: 'feduraaa.json' tripleo_container_manage_clean_orphans: false tasks: - include_role: name: tripleo-container-manage post_tasks: - name: Verify that all containers still exist when: - not ansible_check_mode|bool block: - name: Check for fedora container command: podman container exists fedora - name: Check if tripleo_fedora systemd service is active command: systemctl is-active --quiet tripleo_fedora register: tripleo_fedora_active_result - name: Assert that tripleo_fedora systemd service is active assert: that: - tripleo_fedora_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd service is not active' success_msg: 'tripleo_fedora systemd service is active' - name: Check if tripleo_fedora systemd healthcheck service is active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result - name: Assert that tripleo_fedora systemd healthcheck service is active assert: that: - tripleo_fedora_healthcheck_active_result.rc == 0 fail_msg: 'tripleo_fedora systemd healthcheck service is not active' success_msg: 'tripleo_fedora systemd healthcheck service is active' - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Check for fedora_three container command: podman container exists fedora_three - name: Test a container removal become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: 'fedora_*.json' tripleo_container_manage_systemd_order: true tasks: - name: Remove fedora container config file: path: '/tmp/container-configs/fedora.json' state: absent - include_role: name: tripleo-container-manage post_tasks: - name: Verify that all containers still exist when: - not ansible_check_mode|bool block: - name: Check that fedora container was removed command: podman container exists fedora register: container_exist failed_when: container_exist.rc == 0 - name: Check if tripleo_fedora systemd service is still active command: systemctl is-active --quiet tripleo_fedora register: tripleo_fedora_active_result failed_when: tripleo_fedora_active_result.rc == 0 - name: Check if tripleo_fedora systemd healthcheck service is still active command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer register: tripleo_fedora_healthcheck_active_result failed_when: tripleo_fedora_healthcheck_active_result.rc == 0 - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Check for fedora_three container command: podman container exists fedora_three - name: Test a container update become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: 'fedora_*.json' tripleo_container_manage_systemd_order: true tasks: - name: Modify the fedora_bis container config copy: content: | { "image": "fedora:rawhide", "net": "host", "command": "sleep 10" } dest: '/tmp/container-configs/fedora_bis.json' - include_role: name: tripleo-container-manage post_tasks: - name: Verify that Fedora bis container was re-created correctly when: - not ansible_check_mode|bool block: - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Gather facts about fedora_bis container podman_container_info: name: fedora_bis register: fedora_bis_infos - name: Assert that fedora_bis container has the right image assert: that: - "'fedora:rawhide' in fedora_bis_infos.containers.0.ImageName" fail_msg: 'fedora_bis container has wrong image' success_msg: 'fedora_bis container has the right image' - name: Check for fedora_three container command: podman container exists fedora_three when: - not ansible_check_mode|bool - name: Test a container config override become: true hosts: all gather_facts: false vars: tripleo_container_manage_config: '/tmp/container-configs' tripleo_container_manage_debug: true tripleo_container_manage_config_patterns: 'fedora_*.json' tripleo_container_manage_systemd_order: true tripleo_container_manage_config_overrides: fedora_bis: image: fedora:latest tasks: - include_role: name: tripleo-container-manage post_tasks: - name: Verify that Fedora bis container was re-created correctly when: - not ansible_check_mode|bool block: - name: Check for fedora_bis container command: podman container exists fedora_bis - name: Gather facts about fedora_bis container podman_container_info: name: fedora_bis register: fedora_bis_infos - name: Assert that fedora_bis container has the right image assert: that: - "'fedora:latest' in fedora_bis_infos.containers.0.ImageName" fail_msg: 'fedora_bis container has wrong image' success_msg: 'fedora_bis container has the right image' - name: Check for fedora_three container command: podman container exists fedora_three when: - not ansible_check_mode|bool