2023-12-03 14:39:24 +00:00
|
|
|
---
|
|
|
|
- name: Verify
|
|
|
|
hosts: all
|
|
|
|
gather_facts: true
|
2023-12-04 22:10:02 +00:00
|
|
|
become: true
|
2023-12-03 14:39:24 +00:00
|
|
|
tasks:
|
2023-12-05 18:23:38 +00:00
|
|
|
- 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) == ''
|
|
|
|
|
|
|
|
- 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'
|