|
| 1 | +--- |
| 2 | +- name: Verify Photon deployment |
| 3 | + hosts: all |
| 4 | + gather_facts: false |
| 5 | + vars: |
| 6 | + photon_database_path: /tmp/molecule-photon-data |
| 7 | + photon_network: molecule-traefik |
| 8 | + tasks: |
| 9 | + - name: Gather numeric UID and GID of the host photon user |
| 10 | + ansible.builtin.getent: |
| 11 | + database: passwd |
| 12 | + key: photon |
| 13 | + |
| 14 | + - name: Inspect Photon data directory |
| 15 | + ansible.builtin.stat: |
| 16 | + path: "{{ photon_database_path }}" |
| 17 | + register: photon_data_directory |
| 18 | + |
| 19 | + - name: Assert Photon data directory belongs to the Photon user |
| 20 | + ansible.builtin.assert: |
| 21 | + that: |
| 22 | + - photon_data_directory.stat.pw_name == 'photon' |
| 23 | + - photon_data_directory.stat.gr_name == 'photon' |
| 24 | + |
| 25 | + - name: Inspect Photon container |
| 26 | + community.docker.docker_container_info: |
| 27 | + name: photon |
| 28 | + register: photon_container |
| 29 | + |
| 30 | + - name: Assert Photon container configuration |
| 31 | + ansible.builtin.assert: |
| 32 | + that: |
| 33 | + - photon_container.container.State.Status == 'running' |
| 34 | + - photon_container.container.State.Health.Status == 'healthy' |
| 35 | + - photon_container.container.Config.Image == 'rtuszik/photon-docker:latest' |
| 36 | + - photon_container.container.HostConfig.RestartPolicy.Name == 'always' |
| 37 | + - >- |
| 38 | + photon_container.container.HostConfig.PortBindings is none or |
| 39 | + photon_container.container.HostConfig.PortBindings | length == 0 |
| 40 | + - photon_network in photon_container.container.NetworkSettings.Networks |
| 41 | + - >- |
| 42 | + photon_container.container.Mounts | selectattr('Destination', 'equalto', |
| 43 | + '/photon/data') | list | length == 1 |
| 44 | + - >- |
| 45 | + (photon_container.container.Mounts | |
| 46 | + selectattr('Destination', 'equalto', '/photon/data') | |
| 47 | + map(attribute='Source') | first) == photon_database_path |
| 48 | + - photon_container.container.Config.Env is contains('PUID=' ~ ansible_facts.getent_passwd['photon'][1]) |
| 49 | + - photon_container.container.Config.Env is contains('PGID=' ~ ansible_facts.getent_passwd['photon'][2]) |
| 50 | + - photon_container.container.Config.Env is contains('UPDATE_STRATEGY=SEQUENTIAL') |
| 51 | + - photon_container.container.Config.Env is contains('UPDATE_INTERVAL=30d') |
| 52 | + - photon_container.container.Config.Labels['traefik.enable'] == 'true' |
| 53 | + - photon_container.container.Config.Labels['traefik.http.routers.photon.rule'] == 'Host(`photon.test`)' |
| 54 | + - photon_container.container.Config.Labels['traefik.http.routers.photon.tls'] == 'true' |
| 55 | + - photon_container.container.Config.Labels['traefik.http.routers.photon.tls.certresolver'] == 'le' |
| 56 | + - photon_container.container.Config.Labels['traefik.http.services.photon.loadbalancer.server.port'] == '2322' |
| 57 | + |
| 58 | + - name: Check Photon API endpoint from the container |
| 59 | + community.docker.docker_container_exec: |
| 60 | + container: photon |
| 61 | + command: curl -fsS http://127.0.0.1:2322/ |
| 62 | + register: photon_api_check |
| 63 | + changed_when: false |
| 64 | + |
| 65 | + - name: Assert Photon API endpoint succeeded |
| 66 | + ansible.builtin.assert: |
| 67 | + that: photon_api_check.rc == 0 |
| 68 | + |
| 69 | + - name: Inspect Photon service process user |
| 70 | + community.docker.docker_container_exec: |
| 71 | + container: photon |
| 72 | + command: >- |
| 73 | + sh -c "awk '/^Uid:/ { print $2 }' /proc/1/status" |
| 74 | + register: photon_process_uid |
| 75 | + changed_when: false |
| 76 | + |
| 77 | + - name: Assert Photon service process uses the host photon user |
| 78 | + ansible.builtin.assert: |
| 79 | + that: |
| 80 | + - photon_process_uid.stdout == ansible_facts.getent_passwd['photon'][1] |
0 commit comments