diff --git a/defaults/main.yml b/defaults/main.yml index 03baa07..630e8e1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,12 +1,12 @@ --- # defaults file for deploy_haproxy deploy_haproxy_deploy_method: host # deployment method, either host or docker -deploy_haproxy_version: "2.6" +deploy_haproxy_version: latest deploy_haproxy_env_variables: {} +deploy_haproxy_start_service: true # docker-only options -deploy_haproxy_container_expose_ports: [] deploy_haproxy_extra_container_volumes: [] # Options from the "default" config block in haproxy.cfg @@ -29,39 +29,44 @@ deploy_haproxy_defaults: - timeout server 5000 deploy_haproxy_frontends: - - name: default - options: - - description default frontend - - mode http - - bind :80 - - default_backend default + [] + # - name: default + # options: + # - description default frontend + # - mode http + # - bind :80 + # - default_backend default deploy_haproxy_backends: - - name: default - options: - - description default backend - - option forwardfor - - option httpchk - - http-check send meth GET uri / - - server srv_nginx1 172.17.0.4:80 check inter 5s - - server srv_nginx2 172.17.0.3:80 check inter 5s + [] + # - name: default + # options: + # - description default backend + # - option forwardfor + # - option httpchk + # - http-check send meth GET uri / + # - server srv_nginx1 172.17.0.4:80 check inter 5s + # - server srv_nginx2 172.17.0.3:80 check inter 5s + +# listen configuration blocks +# the default values expose a monitoring listener on all interfaces on port 9000 +# /stats returns the haproxy dashboard (please change the user and password in the configuration) +# /health returns a 200 OK response as long as haproxy is alive and well +# /metrics returns prometheus metrics for the haproxy instance deploy_haproxy_listen: - - name: stats + - name: monitoring options: - bind :9000 - mode http + - option httpchk - stats enable - stats uri /stats - stats refresh 30s - stats show-desc - stats show-legends - stats auth admin:password - - name: health - options: - - bind :8000 - - mode http - - option httpchk - http-check send meth GET uri /health ver HTTP/1.1 hdr Host localhost - http-check expect status 200 - acl health_check_ok nbsrv() ge 1 - monitor-uri /health + - http-request use-service prometheus-exporter if { path /metrics } diff --git a/handlers/main.yml b/handlers/main.yml index a9e23f5..b1e3918 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -17,3 +17,4 @@ state: restarted listen: "systemctl-restart-haproxy" throttle: 1 + when: deploy_haproxy_start_service diff --git a/molecule/default_vagrant/group_vars/all.yml b/molecule/default_vagrant/group_vars/all.yml new file mode 100644 index 0000000..3d23529 --- /dev/null +++ b/molecule/default_vagrant/group_vars/all.yml @@ -0,0 +1,69 @@ +--- +deploy_haproxy_deploy_method: docker # deployment method, either host or docker +deploy_haproxy_version: "2.8" + +deploy_haproxy_env_variables: {} +deploy_haproxy_start_service: true + +# docker-only options +deploy_haproxy_extra_container_volumes: [] + +# Options from the "default" config block in haproxy.cfg +# The default values here are usually set, but you can change any of them. +deploy_haproxy_global: + - log /dev/log local0 + - log /dev/log local1 notice + - stats socket {{ deploy_haproxy_socket }} level admin + - chroot {{ deploy_haproxy_chroot }} + - daemon + - description hashistack haproxy + +deploy_haproxy_defaults: + - log global + - mode http + - option httplog + - option dontlognull + - timeout connect 5000 + - timeout client 5000 + - timeout server 5000 + +deploy_haproxy_frontends: + - name: default + options: + - description default frontend + - mode http + - bind :1024 + - default_backend default + +deploy_haproxy_backends: + - name: default + options: + - description default backend + - option forwardfor + - option httpchk + - http-check send meth GET uri / + - server srv_nginx1 172.17.0.3:80 check inter 5s + - server srv_nginx2 172.17.0.2:80 check inter 5s + +# listen configuration blocks +# the default values expose a monitoring listener on all interfaces on port 9000 +# /stats returns the haproxy dashboard (please change the user and password in the configuration) +# /health returns a 200 OK response as long as haproxy is alive and well +# /metrics returns prometheus metrics for the haproxy instance +deploy_haproxy_listen: + - name: monitoring + options: + - bind :9000 + - mode http + - option httpchk + - stats enable + - stats uri /stats + - stats refresh 30s + - stats show-desc + - stats show-legends + - stats auth admin:password + - http-check send meth GET uri /health ver HTTP/1.1 hdr Host localhost + - http-check expect status 200 + - acl health_check_ok nbsrv() ge 1 + - monitor-uri /health + - http-request use-service prometheus-exporter if { path /metrics } diff --git a/molecule/default_vagrant/prepare.yml b/molecule/default_vagrant/prepare.yml new file mode 100644 index 0000000..7f58328 --- /dev/null +++ b/molecule/default_vagrant/prepare.yml @@ -0,0 +1,10 @@ +--- +- name: Prepare + hosts: all + become: true + tasks: + - name: "Include ednxzu.install_docker" + ansible.builtin.include_role: + name: ednxzu.install_docker + vars: + install_docker_python_packages: true diff --git a/molecule/default_vagrant/requirements.yml b/molecule/default_vagrant/requirements.yml new file mode 100644 index 0000000..1316891 --- /dev/null +++ b/molecule/default_vagrant/requirements.yml @@ -0,0 +1,6 @@ +--- +# requirements file for molecule +roles: + - name: ednxzu.manage_repositories + - name: ednxzu.manage_apt_packages + - name: ednxzu.install_docker diff --git a/tasks/install_docker.yml b/tasks/install_docker.yml index 20f33c5..5e93028 100644 --- a/tasks/install_docker.yml +++ b/tasks/install_docker.yml @@ -2,18 +2,18 @@ # task/install_docker file for deploy_haproxy - name: "Update container volume list" ansible.builtin.set_fact: - hashi_consul_container_volume_map: "{{ hashi_consul_container_volume_map + hashi_consul_extra_container_volumes }}" + deploy_haproxy_container_volume_map: "{{ deploy_haproxy_container_volume_map + deploy_haproxy_extra_container_volumes }}" - name: "Include ednxzu.docker_systemd_service" ansible.builtin.include_role: name: ednxzu.docker_systemd_service vars: - docker_systemd_service_container_name: "consul" - docker_systemd_service_image: "{{ hashi_consul_docker_image }}:{{ hashi_consul_version }}" - docker_systemd_service_container_env: "{{ hashi_consul_env_variables }}" + docker_systemd_service_container_name: "haproxy" + docker_systemd_service_image: "{{ deploy_haproxy_docker_image }}:{{ deploy_haproxy_version }}" + docker_systemd_service_container_env: "{{ deploy_haproxy_env_variables }}" docker_systemd_service_flags: - network: host - - volume: "{{ hashi_consul_container_volume_map }}" + - volume: "{{ deploy_haproxy_container_volume_map }}" docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" - docker_systemd_service_state: "{{ 'started' if hashi_consul_start_service else 'stopped'}}" - docker_systemd_service_restart: "{{ true if hashi_consul_start_service else false}}" + docker_systemd_service_state: "{{ 'started' if deploy_haproxy_start_service else 'stopped'}}" + docker_systemd_service_restart: "{{ true if deploy_haproxy_start_service else false}}" diff --git a/tasks/main.yml b/tasks/main.yml index 581d096..08d7320 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,6 +5,14 @@ - name: "Import install_host.yml" ansible.builtin.include_tasks: install_host.yml + when: deploy_haproxy_deploy_method == 'host' - name: "Import configure.yml" ansible.builtin.include_tasks: configure.yml + +- name: "Import install_docker.yml" + ansible.builtin.include_tasks: "install_docker.yml" + when: deploy_haproxy_deploy_method == 'docker' + +- name: "Flush handlers" + ansible.builtin.meta: flush_handlers diff --git a/vars/main.yml b/vars/main.yml index 76d1f0a..67aff92 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,12 +3,15 @@ deploy_haproxy_config_dir: /etc/haproxy deploy_haproxy_socket: /var/lib/haproxy/stats deploy_haproxy_chroot: /var/lib/haproxy -deploy_haproxy_user: haproxy -deploy_haproxy_group: haproxy +deploy_haproxy_user: "{{ '99' if deploy_haproxy_deploy_method == 'docker' else 'haproxy' }}" +deploy_haproxy_group: "{{ '99' if deploy_haproxy_deploy_method == 'docker' else 'haproxy' }}" deploy_haproxy_service_name: "haproxy{{ '_container' if deploy_haproxy_deploy_method == 'docker' }}" -deploy_haproxy_docker_image: haproxy +deploy_haproxy_docker_image: haproxytech/haproxy-debian deploy_haproxy_version_map: latest: "2.9" +deploy_haproxy_container_volume_map: + - "{{ deploy_haproxy_config_dir }}:/usr/local/etc/haproxy" + # - "{{ deploy_haproxy_chroot }}:{{ deploy_haproxy_chroot }}" deploy_haproxy_repository: debian: