service_status¶
About The Role¶
An Ansible role to detect services status on the target host(s).
Requirements¶
No requirements.
Dependencies¶
No dependencies.
Example Playbook¶
- hosts: localhost
gather_facts: false
roles:
- service_status
License¶
Apache
Full Description¶
Role Documentation¶
Welcome to the ‘service_status’ role documentation.
Molecule Scenarios¶
Molecule is being used to test the ‘service_status’ role. The following section highlights the drivers in service and provides an example playbook showing how the role is leveraged.
- Driver: podman:
- Driver: podman:
- Driver: docker:
- Driver: podman:
Scenario: podman¶
Molecule Platform(s)¶
- name: centos
hostname: centos
image: centos/centos:stream8
registry:
url: quay.io
dockerfile: ../../../../../.config/molecule/Dockerfile
pkg_extras: python*-setuptools python*-pyyaml
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
privileged: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits:
- host
Molecule Inventory¶
hosts:
all:
hosts:
centos:
ansible_python_interpreter: /usr/bin/python3
Example podman playbook¶
- name: Converge
hosts: all
gather_facts: false
vars:
service_status_podman_opt: --storage-driver=vfs
tasks:
- name: Check podman container state
block:
- name: Detect failed podman containers
include_role:
name: service_status
tasks_from: containers.yaml
rescue:
- name: Clear host errors
meta: clear_host_errors
- name: Test output
debug:
msg: |
Properly detected failed container
- name: End play now
meta: end_play
- name: Fail if we get to this point
fail:
msg: |
Did not detect failed container
Scenario: default¶
Molecule Platform(s)¶
- name: centos8
hostname: centos8
image: centos/centos:stream8
registry:
url: quay.io
dockerfile: ../../../../../.config/molecule/Dockerfile
command: /sbin/init
pkg_extras: python*-setuptools python*-pyyaml
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
privileged: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits:
- host
Molecule Inventory¶
hosts:
all:
hosts:
centos:
ansible_python_interpreter: /usr/bin/python3
Example default playbook¶
- name: Converge
hosts: all
gather_facts: false
tasks:
- name: Full check with defaults
include_role:
name: service_status
Scenario: docker¶
Molecule Platform(s)¶
- name: centos8
hostname: centos8
image: centos/centos:stream8
registry:
url: quay.io
dockerfile: ../../../../../.config/molecule/Dockerfile
pkg_extras: python*-setuptools python*-pyyaml python*-libselinux
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
Molecule Inventory¶
hosts:
all:
hosts:
centos:
ansible_python_interpreter: /usr/bin/python3
Example docker playbook¶
- name: Converge
hosts: all
gather_facts: false
become: true
tasks:
- name: Check containers - docker version, no service
include_role:
name: service_status
tasks_from: containers.yaml
- name: Check containers - docker version, with service
block:
- name: Activate docker service
service:
name: docker
state: started
enabled: true
- name: Catch failure
block:
- name: Run check
include_role:
name: service_status
tasks_from: containers.yaml
rescue:
- name: Clear host errors
meta: clear_host_errors
- name: Test output
debug:
msg: |
Success finding broken containers
- name: End play
meta: end_play
- name: Fail if this point is reached
fail:
msg: |
Did not find broken containers
Scenario: systemd¶
Molecule Platform(s)¶
- name: centos8
hostname: centos8
image: centos/centos:stream8
registry:
url: quay.io
dockerfile: ../../../../../.config/molecule/Dockerfile
pkg_extras: python*-setuptools python*-pyyaml
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
privileged: true
command: /sbin/init
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
ulimits:
- host
Molecule Inventory¶
hosts:
all:
hosts:
centos:
ansible_python_interpreter: /usr/bin/python3
Example systemd playbook¶
- name: Converge
hosts: all
gather_facts: false
tasks:
- name: Check service
block:
- name: Run validation
include_role:
name: service_status
tasks_from: systemd.yaml
rescue:
- name: Clear errors
meta: clear_host_errors
- name: Test output
debug:
msg: |
Successfully detected failed unit
- name: End play
meta: end_play
- name: Fail if this point is reached
fail:
msg: |
Did not detect failed unit