install_docker/molecule/with_custom_config/verify.yml

127 lines
4.8 KiB
YAML

---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: "Test: file /etc/hosts"
block:
- name: "Stat file /etc/hosts"
ansible.builtin.stat:
path: "/etc/hosts"
register: stat_etc_hosts
- name: "Verify file /etc/hosts"
ansible.builtin.assert:
that:
- stat_etc_hosts.stat.exists
- stat_etc_hosts.stat.isreg
- stat_etc_hosts.stat.pw_name == 'root'
- stat_etc_hosts.stat.gr_name == 'root'
- name: "Test: service docker"
block:
- name: "Get service docker"
ansible.builtin.service_facts:
- name: "Stat file /lib/systemd/system/docker.service"
ansible.builtin.stat:
path: "/lib/systemd/system/docker.service"
register: stat_lib_systemd_system_docker_service
- name: "Verify service docker"
ansible.builtin.assert:
that:
- stat_lib_systemd_system_docker_service.stat.exists
- stat_lib_systemd_system_docker_service.stat.isreg
- stat_lib_systemd_system_docker_service.stat.pw_name == 'root'
- stat_lib_systemd_system_docker_service.stat.gr_name == 'root'
- stat_lib_systemd_system_docker_service.stat.mode == '0644'
- ansible_facts.services['docker.service'] is defined
- ansible_facts.services['docker.service']['source'] == 'systemd'
- ansible_facts.services['docker.service']['state'] == 'running'
- ansible_facts.services['docker.service']['status'] == 'enabled'
- name: "Test: file /etc/docker/daemon.json"
block:
- name: "Stat directory /etc/docker"
ansible.builtin.stat:
path: "/etc/docker"
register: stat_etc_docker
- name: "Stat file /etc/docker/daemon.json"
ansible.builtin.stat:
path: "/etc/docker/daemon.json"
register: stat_etc_docker_docker_json
- name: "Slurp file /etc/docker/daemon.json"
ansible.builtin.slurp:
src: "/etc/docker/daemon.json"
register: slurp_etc_docker_docker_json
- name: "Verify directory /etc/docker"
ansible.builtin.assert:
that:
- stat_etc_docker.stat.exists
- stat_etc_docker.stat.isdir
- stat_etc_docker.stat.pw_name == 'root'
- stat_etc_docker.stat.gr_name == 'root'
- stat_etc_docker.stat.mode == '0755'
- stat_etc_docker_docker_json.stat.exists
- stat_etc_docker_docker_json.stat.isreg
- stat_etc_docker_docker_json.stat.pw_name == 'root'
- stat_etc_docker_docker_json.stat.gr_name == 'root'
- stat_etc_docker_docker_json.stat.mode == '0644'
- "'\"data-root\": \"/opt/docker\"' in (slurp_etc_docker_docker_json.content|b64decode)"
- name: "Test: interaction docker"
block:
- name: "Command docker ps"
ansible.builtin.command: "docker ps"
changed_when: false
register: docker_ps
- name: "Verify docker interaction"
ansible.builtin.assert:
that:
- docker_ps.stdout == 'CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES'
- name: "Test: file /usr/local/bin/docker-compose"
block:
- name: "Stat file /usr/local/bin/docker-compose"
ansible.builtin.stat:
path: "/usr/local/bin/docker-compose"
register: stat_url_local_bin_docker_compose
- name: "Command docker-compose --version"
ansible.builtin.command: "docker-compose --version"
changed_when: false
register: docker_compose_version
- name: "Verify file /usr/local/bin/docker-compose"
ansible.builtin.assert:
that:
- docker_compose_version.stdout | regex_search('^Docker Compose version v\\d+\\.\\d+\\.\\d+$')
- stat_url_local_bin_docker_compose.stat.exists
- stat_url_local_bin_docker_compose.stat.isreg
- stat_url_local_bin_docker_compose.stat.pw_name == 'root'
- stat_url_local_bin_docker_compose.stat.gr_name == 'root'
- stat_url_local_bin_docker_compose.stat.mode == '0755'
- name: "Test: python package docker"
block:
- name: "Command pip3 list -o"
ansible.builtin.command: "pip3 list -o"
changed_when: false
register: pip3_list_outdated
- name: "Command pip3 list -u"
ansible.builtin.command: "pip3 list -u"
changed_when: false
register: pip3_list_uptodate
- name: "Verify python package docker"
ansible.builtin.assert:
that:
- "'docker' not in pip3_list_outdated.stdout"
- "'docker' in pip3_list_uptodate.stdout"