docker_systemd_service/molecule/default/verify.yml
Bertrand Lanson ffbb6157ef
All checks were successful
test / Retrieve Credentials (pull_request) Successful in 2s
development / Check commit compliance (push) Successful in 5s
pull-requests-open / Check commit compliance (pull_request) Successful in 5s
test / end_to_end_role (default, debian11) (pull_request) Successful in 39s
test / end_to_end_role (default, debian12) (pull_request) Successful in 40s
test / end_to_end_role (default, ubuntu2004) (pull_request) Successful in 40s
test / end_to_end_role (default, ubuntu2204) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, debian11) (pull_request) Successful in 37s
test / end_to_end_role (default, ubuntu2404) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2204) (pull_request) Successful in 38s
test / end_to_end_role (with_custom_flags, debian12) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2004) (pull_request) Successful in 39s
test / end_to_end_role (with_custom_flags, ubuntu2404) (pull_request) Successful in 38s
feat: only allow starting and managing running services.
destroying/removing services should be handled separately, most likely by
the end user's custom code, to avoid data loss, etc...
2024-11-09 13:24:14 +01:00

79 lines
3.2 KiB
YAML

---
- name: Verify
hosts: all
gather_facts: true
become: true
tasks:
- name: "Test: file /etc/default/nginx"
block:
- name: "Stat file /etc/default/nginx"
ansible.builtin.stat:
path: "/etc/default/nginx"
register: stat_etc_default_nginx
- name: "Slurp file /etc/default/nginx"
ansible.builtin.slurp:
src: "/etc/default/nginx"
register: slurp_etc_default_nginx
- name: "Verify file /etc/systemd/system/nginx_container.service"
ansible.builtin.assert:
that:
- stat_etc_default_nginx.stat.exists
- stat_etc_default_nginx.stat.isreg
- stat_etc_default_nginx.stat.pw_name == 'root'
- stat_etc_default_nginx.stat.gr_name == 'root'
- stat_etc_default_nginx.stat.mode == '0600'
- (slurp_etc_default_nginx.content|b64decode) == '\n'
- name: "Test: service nginx_container"
block:
- name: "Get service nginx_container"
ansible.builtin.service_facts:
- name: "Stat file /etc/systemd/system/nginx_container.service"
ansible.builtin.stat:
path: "/etc/systemd/system/nginx_container.service"
register: stat_etc_systemd_system_nginx_container_service
- name: "Slurp file /etc/systemd/system/nginx_container.service"
ansible.builtin.slurp:
src: "/etc/systemd/system/nginx_container.service"
register: slurp_etc_systemd_system_nginx_container_service
- name: "Verify service nginx_container"
vars:
nginx_expected_service_file: |
# Ansible managed: Do NOT edit this file manually!
[Unit]
After=docker.service
PartOf=docker.service
Requires=docker.service
[Service]
EnvironmentFile=/etc/default/nginx
ExecStartPre=-/usr/bin/docker rm -f nginx
ExecStart=/usr/bin/docker run --name nginx \
--rm \
--env-file /etc/default/nginx \
nginx
ExecStop=/usr/bin/docker stop nginx
SyslogIdentifier=nginx
Restart=always
RestartSec=10s
[Install]
WantedBy=docker.service
ansible.builtin.assert:
that:
- stat_etc_systemd_system_nginx_container_service.stat.exists
- stat_etc_systemd_system_nginx_container_service.stat.isreg
- stat_etc_systemd_system_nginx_container_service.stat.pw_name == 'root'
- stat_etc_systemd_system_nginx_container_service.stat.gr_name == 'root'
- stat_etc_systemd_system_nginx_container_service.stat.mode == '0644'
- (slurp_etc_systemd_system_nginx_container_service.content|b64decode) == nginx_expected_service_file
- ansible_facts.services['nginx_container.service'] is defined
- ansible_facts.services['nginx_container.service']['source'] == 'systemd'
- ansible_facts.services['nginx_container.service']['state'] == 'inactive'
- ansible_facts.services['nginx_container.service']['status'] == 'enabled'