{"id":40993429,"url":"https://github.com/hellofresh/ansible-consul","last_synced_at":"2026-01-22T08:04:34.910Z","repository":{"id":76875758,"uuid":"51755741","full_name":"hellofresh/ansible-consul","owner":"hellofresh","description":"Ansible Role to install and configure consul","archived":false,"fork":false,"pushed_at":"2025-10-07T04:59:05.000Z","size":221,"stargazers_count":16,"open_issues_count":4,"forks_count":10,"subscribers_count":231,"default_branch":"master","last_synced_at":"2025-12-01T06:49:40.281Z","etag":null,"topics":["ansible-role","consul","consul-template","open-source","service-discovery","wiz-reliability-platform-cloud-runtime"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellofresh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-02-15T13:01:54.000Z","updated_at":"2025-10-07T04:59:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0df9c69-ab1e-464a-964b-b6781192dcfa","html_url":"https://github.com/hellofresh/ansible-consul","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/hellofresh/ansible-consul","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellofresh%2Fansible-consul","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellofresh%2Fansible-consul/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellofresh%2Fansible-consul/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellofresh%2Fansible-consul/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellofresh","download_url":"https://codeload.github.com/hellofresh/ansible-consul/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellofresh%2Fansible-consul/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28658989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible-role","consul","consul-template","open-source","service-discovery","wiz-reliability-platform-cloud-runtime"],"created_at":"2026-01-22T08:04:16.781Z","updated_at":"2026-01-22T08:04:34.905Z","avatar_url":"https://github.com/hellofresh.png","language":"Ruby","readme":"--------\n# Ansible Consul Role\n[![Build Status](https://travis-ci.org/hellofresh/ansible-consul.svg?branch=master)](https://travis-ci.org/hellofresh/ansible-consul)\n\n`consul` is an ansible role to install and manage consul services and client side load balancing.\n\n\n## Overview\n\nThis is an opinionated setup of consul. That manages services discovery and client side load balancing. It deploys HAproxy with each consumer and use consul template.\n\n```\n                  +--------------+\n                  | Consul UI    |\n                  | Consul Server|\n                  |              |\n                  +--------------+\n                   (Consul Server)\n\n+----------------+            +--------------+\n|HAproxy         |            | Consul(Agent)|\n|Consul(Agent)   |            | App(Producer)|\n|consul(template)|            |              |\n|App(Consumer)   |            |              |\n+----------------+            +--------------+\n    (Consumer)                    (Producer)\n```\n\nUsing with AMI\n--------------\n\nWhen the role is used to provision AMI image, ensure the following variables are set to these specific values\n\n```yaml\nconsul_start_service: false         # Required: Prevent consul from starting at provision time\nconsul_node_name: auto              # Required: read node name from cloud meta-data\nconsul_network_bind: auto           # Required: read private IP from cloud meta-data\nconsul_network_autobind: false      # Required: disable provision time IP address discovery\nconsul_node_name_prefix: \"service-\" # Optional: node name prefix\n```\n\nRequirements\n------------\n\n - Developed for Ansible 2.X\n - Controller should have python-netaddr\n\nRole Variables\n--------------\n\n```yaml\n---\n\nconsul_node_name                    : \"{{ inventory_hostname }}\"\n\n# Type of installation\nconsul_server                       : false\nconsul_consumer                     : false\nconsul_producer                     : false\nconsul_ui                           : false\n#\nconsul_consumer_services            : []\nconsul_producer_services            : []\n\n# Consul Domain\nconsul_datacenter                   : \"default\"\nconsul_domain                       : \"consul.\"\n\n#consul_start_join                   : [ \"127.0.0.1\" ]\nconsul_rejoin_after_leave           : true\nconsul_leave_on_terminate           : false\n\n#Consul log\nconsul_log_level                    : \"INFO\"\nconsul_log_syslog                   : false\n\n# Consul Network                    :\nconsul_network_bind                 : \"\" # \"0.0.0.0\"\nconsul_network_autobind             : true\n#consul_network_autobind_range       : \"192.168.56.0/24\"\nconsul_network_autobind_type        : \"private\" # \"\" or private or public\nconsul_client_addr                  : \"127.0.0.1\"\n\n# Consul dir structure\nconsul_home_dir                     : \"/opt/consul\"\nconsul_bin_dir                      : \"{{ consul_home_dir }}/bin\"\nconsul_tmp_dir                      : \"{{ consul_home_dir }}/tmp\"\nconsul_data_dir                     : \"{{ consul_home_dir }}/data\"\nconsul_template_dir                 : \"{{ consul_home_dir }}/templates\"\nconsul_log_dir                      : \"/var/log/consul\"\nconsul_config_dir                   : \"/etc/consul.d\"\n# Consul files\nconsul_config_agent_file            : \"/etc/consul.conf\"\nconsul_config_template_file         : \"/etc/consul-template.conf\"\nconsul_agent_log_file               : \"{{ consul_log_dir }}/consul-agent.log\"\nconsul_template_log_file            : \"{{ consul_log_dir }}/consul-template.log\"\nconsul_template_haproxy_file        : \"{{ consul_template_dir }}/consul_template.cnf\"\n\n# Consul user/Group\nconsul_user                         : \"consul\"\nconsul_group                        : \"consul\"\n\n# Consul template\nconsul_template_consul_server       : \"127.0.0.1\"\nconsul_template_consul_port         : \"8500\"\nconsul_template_templates           :\n                                      - source      : \"{{ consul_template_haproxy_file }}\"\n                                        destination : \"/etc/haproxy/haproxy.cfg\"\n                                        command     : \"haproxy -f /etc/haproxy/haproxy.cfg -c \u0026\u0026 sudo service haproxy reload\"\n                                        jtemplate   : \"haproxy.ctmp.j2\"\n\n## Telemetry\n# Enable telemetry\nconsul_telemetry                    : False\n# StatsD server address and port (address:port)\nconsul_statsd_address               : \"\"\n---\n\nconsul_agent_version                : \"0.7.5\"\nconsul_template_version             : \"0.18.1\"\n\nconsul_node_name                    : \"{{ inventory_hostname }}\"\n\n# Type of installation\nconsul_server                       : false\nconsul_consumer                     : false\nconsul_producer                     : false\nconsul_ui                           : false\n\n#\nconsul_consumer_services            : []\nconsul_producer_services            : []\n\n# Consul Domain\nconsul_datacenter                   : \"default\"\nconsul_domain                       : \"consul.\"\n\n#consul_start_join                   : [ \"127.0.0.1\" ]\nconsul_servers_list                 : [ \"127.0.0.1\" ] # you can use ansible groups \"{{ groups['consul_servers'] }}\"\nconsul_rejoin_after_leave           : true\nconsul_leave_on_terminate           : false\n# Retry Options\nconsul_retry_join                   : false\nconsul_retry_interval               : 30s\nconsul_retry_max                    : 0\n# Consul log\nconsul_log_level                    : \"INFO\"\nconsul_log_syslog                   : false\n\nconsul_server_port_server           : 8300\nconsul_http_port                    : 8500\nconsul_https_port                   : -1\n\n# Consul Network                    :\nconsul_network_bind                 : \"\" # \"0.0.0.0\"\nconsul_network_autobind             : true\n#consul_network_autobind_range       : \"192.168.56.0/24\"\nconsul_network_autobind_type        : \"private\" # \"\" or private or public\nconsul_client_addr                  : \"127.0.0.1\"\n\n# Consul dir structure\nconsul_home_dir                     : \"/opt/consul\"\nconsul_bin_dir                      : \"{{ consul_home_dir }}/bin\"\nconsul_tmp_dir                      : \"{{ consul_home_dir }}/tmp\"\nconsul_data_dir                     : \"{{ consul_home_dir }}/data\"\nconsul_template_dir                 : \"{{ consul_home_dir }}/templates\"\nconsul_log_dir                      : \"/var/log/consul\"\nconsul_config_dir                   : \"/etc/consul.d\"\n# if you leave emtpy only \"healthy\" and passing services will be returned. You can also use \"passing,warning\" or \"all\"\n# For more info check https://github.com/hashicorp/consul-template#service\nconsul_template_service_options     : \"\"\n\n# Consul files\nconsul_config_agent_file            : \"/etc/consul.conf\"\nconsul_config_template_file         : \"/etc/consul-template.conf\"\nconsul_agent_log_file               : \"{{ consul_log_dir }}/consul-agent.log\"\nconsul_template_log_file            : \"{{ consul_log_dir }}/consul-template.log\"\nconsul_template_haproxy_file        : \"{{ consul_template_dir }}/consul_template.cnf\"\n\n# Consul user/Group\nconsul_user                         : \"consul\"\nconsul_group                        : \"consul\"\n\n# Consul template\nconsul_template_consul_server       : \"127.0.0.1\"\nconsul_template_consul_port         : \"8500\"\nconsul_template_templates           :\n                                      - source      : \"{{ consul_template_haproxy_file }}\"\n                                        destination : \"/etc/haproxy/haproxy.cfg\"\n                                        command     : \"{{ consul_bin_dir }}/haproxy-reload\"\n                                        jtemplate   : \"haproxy.ctmp.j2\"\n\nconsul_template_log_level           : \"warn\"\n\nconsul_encrypt                      : \"Tq/xU3fTPyBRoA4R4CxOKg==\"\n\n## Telemetry\nconsul_telemetry                    : False\nconsul_statsd_address               : \"\"\nconsul_statsite_address             : \"\"\nconsul_statsite_prefix              : \"consul\"\nconsul_disable_hostname             : True\n\n## HA Proxy\nconsul_haproxy_ppa_install          : False # By default use packaged version of Haproxy\nconsul_haproxy_ppa_url              : \"ppa:vbernat/haproxy-1.6\"\n## Config global\nconsul_haproxy_user                 : \"haproxy\"\nconsul_haproxy_group                : \"haproxy\"\nconsul_haproxy_maxconn              : \"8192\"\nconsul_haproxy_log                  : [ \"/dev/log\tlocal0\", \"/dev/log\tlocal1 info\" ]\n\nconsul_haproxy_stats_socket         : \"socket /var/lib/haproxy/stats.sock group {{ consul_group }} mode 660 level admin\"\n## Extra global key, value\nconsul_haproxy_extra_global         :\n                                       chroot: \"/var/lib/haproxy\"\n## Config defaults\nconsul_haproxy_default_log          : \"global\"\nconsul_haproxy_default_options      :\n                                      - \"dontlognull\"\n                                      - \"log-separate-errors\"\n                                      - \"redispatch\"\nconsul_haproxy_default_timeout      :\n                                      - \"connect 5s\"\n                                      - \"check   5s\"\n                                      - \"client  120s\"\n                                      - \"server  120s\"\nconsul_haproxy_default_maxconn      : 2000\nconsul_haproxy_default_retries      : 3\nconsul_haproxy_default_balance      : \"roundrobin\"\n## Extra default key, value\n#consul_haproxy_extra_default       :\n\nconsul_haproxy_default_server_options  : \"check inter 10s fastinter 5s downinter 8s rise 3 fall 2\"\n## Config Stats page by default HAproxy will have default stats\nconsul_haproxy_stats_enable         : True\nconsul_haproxy_stats_mode           : \"http\"\nconsul_haproxy_stats_port           : 3212\nconsul_haproxy_stats_uri            : \"/\"\n\n# Ad-hoc commands RUN WITH CARE\nconsul_adhoc_build_raft_peers       : False\n```\n\n\n## Usage\n\nService definition\n----\nThe role expects all services to be listed in `consul_services` dictionary:\n\n```yaml\nconsul_services:\n  hello-app:\n    name: \"hello-app\"\n    tags:\n      - \"env:live\"\n    port: 80\n    local_port: 8032\n    check:\n      script: \"curl localhost:80 \u003e /dev/null 2\u003e\u00261\"\n      interval: \"10s\"\n    haproxy:\n      server_options: \"check inter 10s fastinter 5s downinter 8s rise 3 fall 2\"\n\n  hello-db:\n    name: \"hello-db\"\n    tags:\n      - \"env:live\"\n    port: 3306\n    check:\n      script: \"netstat -ant | grep 3306 | grep -v grep \u003e /dev/null 2\u003e\u00261\"\n      interval: \"10s\"\n    haproxy:\n      server_options: \"check inter 10s fastinter 5s downinter 8s rise 3 fall 2\"\n```\n\nService example\n---------------\n```yaml\n  hello-app:\n    name: \"hello-app\"\n    tags:\n      - \"env:live\"\n    port: 80\n    local_port: 8032\n    check:\n      script: \"curl localhost:80 \u003e /dev/null 2\u003e\u00261\"\n      interval: \"10s\"\n    haproxy:\n      server_options: \"check inter 10s fastinter 5s downinter 8s rise 3 fall 2\"\n```\n`hello-app`:\n\n`name`: service name to announce\n\n`tags`: list of tags to filter by (see tags section)\n\n`port`: port number server part listens on\n\n`local_port`: port number CSLB agent (haproxy) will listen on, if absent equals `port`\n\n`check`: healthcheck script and interval; most of the times as simple as in this example\n\n`haproxy`: haproxy server check definition (https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#5.2-check)\n\n\n### Producer configuration\nDefine list of services you produce (offer to connect to)\n```yaml\nconsul_producer: True\nconsul_producer_services:\n  - hello-app\n  - other-service\n```\nRole will install consul agent and configure it to announce specified services.\n\n### Consumer configuration\nDefine list of services you consume (want to connect to)\n```yaml\nconsul_consumer: True\nconsul_consumer_services:\n  - hello-app\n  - hello-db\n```\nRole will configure consul agent, consul template and haproxy. Haproxy will listen on specified ports, so you would be able to connect to specific service using `127.0.0.1:port`.\n\n### Extended syntax\nIf you want to specify additional parameters you should use extended syntax:\n```yaml\n---\nconsul_producer: True\nconsul_producer_services:\n  # simple syntax\n  - hello-app\n  # extended syntax\n  - name: hello-app\n    add_tags: ['host-specific-tag']\n```\n\n\n```yaml\n---\nconsul_consumer: True\nconsul_consumer_services:\n  # simple syntax\n  - hello-app\n  # extended syntax\n  - name: hello-app\n    tags_contains: \"test\"\n```\n\n\n### Using tags\n\n#### Producer\nYou can specify additional tags for group/host. These tags will be added to a set of tags globally defined to this service.\n\n```yaml\nconsul_producer: True\nconsul_producer_services:\n  - name: hello-app\n    add_tags: ['host-specific-tag']\n```\n\n#### Consumer\nOn consumer side, you can user additional parameters to filter services/nodes by tags.\n\n```yaml\nconsul_consumer: True\nconsul_consumer_services:\n  - name: hello-app\n    tags_contains: \"test\"\n    tag_regex: \"v1.1.*\"\n```\n\n\nRoad map\n-----\n- Support agent retry\n- Support template retry\n\nLicense\n-------\n\nMIT\n\n\nContributors (sorted alphabetically on the first name)\n------------------\n* [Adham Helal](https://github.com/ahelal)\n\n\nSnippets\n-------\nSome snippets of code was taken from various sources. We will try our best to list them.\n\n--------\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://hellofresh.com\"\u003e\n    \u003cimg  width=\"120\" src=\"https://www.hellofresh.de/images/hellofresh/press/HelloFresh_Logo.png\"\u003e\n  \u003c/a\u003e\u003cbr\u003e\n  HelloFresh - More Than Food.\n\u003c/p\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellofresh%2Fansible-consul","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellofresh%2Fansible-consul","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellofresh%2Fansible-consul/lists"}