--- - name: Verify hosts: all gather_facts: true become: true tasks: - name: "Test: directory /etc/haproxy" block: - name: "Stat directory /etc/haproxy" ansible.builtin.stat: path: "/etc/haproxy" register: stat_etc_haproxy - name: "Stat file /etc/default/haproxy" ansible.builtin.stat: path: "/etc/default/haproxy" register: stat_etc_default_haproxy - name: "Stat file /etc/haproxy/haproxy.cfg" ansible.builtin.stat: path: "/etc/haproxy/haproxy.cfg" register: stat_etc_haproxy_haproxy_cfg - name: "Slurp file /etc/haproxy/haproxy.cfg" ansible.builtin.slurp: src: "/etc/haproxy/haproxy.cfg" register: slurp_etc_haproxy_haproxy_cfg - name: "Verify directory /etc/haproxy" ansible.builtin.assert: that: - stat_etc_haproxy.stat.exists - stat_etc_haproxy.stat.isdir - (stat_etc_haproxy.stat.uid | int) == 99 - (stat_etc_haproxy.stat.gid | int) == 99 - stat_etc_haproxy.stat.mode == '0755' - stat_etc_default_haproxy.stat.exists - stat_etc_default_haproxy.stat.isreg - stat_etc_default_haproxy.stat.pw_name == 'root' - stat_etc_default_haproxy.stat.gr_name == 'root' - stat_etc_default_haproxy.stat.mode == '0600' - stat_etc_haproxy_haproxy_cfg.stat.exists - stat_etc_haproxy_haproxy_cfg.stat.isreg - (stat_etc_haproxy_haproxy_cfg.stat.uid | int) == 99 - (stat_etc_haproxy_haproxy_cfg.stat.gid | int) == 99 - stat_etc_haproxy_haproxy_cfg.stat.mode == '0600' - slurp_etc_haproxy_haproxy_cfg.content != '' - name: "Test: directory /var/lib/haproxy" block: - name: "Stat directory /var/lib/haproxy" ansible.builtin.stat: path: "/var/lib/haproxy" register: stat_var_lib_haproxy - name: "Stat socket /var/lib/haproxy/stats" ansible.builtin.stat: path: "/var/lib/haproxy/stats" register: stat_var_lib_haproxy_stats - name: "Verify directory /var/lib/haproxy" ansible.builtin.assert: that: - stat_var_lib_haproxy.stat.exists - stat_var_lib_haproxy.stat.isdir - (stat_var_lib_haproxy.stat.uid | int) == 99 - (stat_var_lib_haproxy.stat.gid | int) == 99 - stat_var_lib_haproxy.stat.mode == '0755' - stat_var_lib_haproxy_stats.stat.exists - stat_var_lib_haproxy_stats.stat.issock - name: "Test: service haproxy" block: - name: "Get service haproxy" ansible.builtin.service_facts: - name: "Stat file /etc/systemd/system/haproxy_container.service" ansible.builtin.stat: path: "/etc/systemd/system/haproxy_container.service" register: stat_etc_systemd_system_haproxy_container_service - name: "Slurp file /etc/systemd/system/haproxy_container.service" ansible.builtin.slurp: src: "/etc/systemd/system/haproxy_container.service" register: slurp_etc_systemd_system_haproxy_container_service - name: "Verify service haproxy" vars: haproxy_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/haproxy ExecStartPre=-/usr/bin/docker rm -f haproxy ExecStart=/usr/bin/docker run --name haproxy \ --rm \ --env-file /etc/default/haproxy \ --network "host" \ --volume "/etc/haproxy:/usr/local/etc/haproxy" \ --volume "/var/lib/haproxy:/var/lib/haproxy" \ haproxytech/haproxy-debian:latest ExecStop=/usr/bin/docker stop haproxy SyslogIdentifier=haproxy Restart=always RestartSec=10s [Install] WantedBy=docker.service ansible.builtin.assert: that: - stat_etc_systemd_system_haproxy_container_service.stat.exists - stat_etc_systemd_system_haproxy_container_service.stat.isreg - stat_etc_systemd_system_haproxy_container_service.stat.pw_name == 'root' - stat_etc_systemd_system_haproxy_container_service.stat.gr_name == 'root' - stat_etc_systemd_system_haproxy_container_service.stat.mode == '0644' - (slurp_etc_systemd_system_haproxy_container_service.content|b64decode) == haproxy_expected_service_file - ansible_facts.services['haproxy_container.service'] is defined - ansible_facts.services['haproxy_container.service']['source'] == 'systemd' - ansible_facts.services['haproxy_container.service']['state'] == 'running' - ansible_facts.services['haproxy_container.service']['status'] == 'enabled' - name: "Test: haproxy endpoints" block: - name: "Get haproxy /health" ansible.builtin.uri: url: "http://127.0.0.1:9000/health" method: GET register: haproxy_health_endpoint - name: "Get haproxy /stats" ansible.builtin.uri: url: "http://127.0.0.1:9000/stats" method: GET force_basic_auth: true url_username: admin url_password: password register: haproxy_stats_endpoint - name: "Get haproxy /metrics" ansible.builtin.uri: url: "http://127.0.0.1:9000/metrics" method: GET register: haproxy_metrics_endpoint - name: "Verify haproxy endpoints" ansible.builtin.assert: that: - haproxy_health_endpoint.status == 200 - haproxy_stats_endpoint.status == 200 - haproxy_metrics_endpoint.status == 200