nahsi.consul

Consul

Install, set up, and manage Consul - a service mesh tool from HashiCorp.

Role Philosophy

Instead of repeating every configuration option as an Ansible variable, Consul's configuration is saved in the Ansible inventory in yaml format:

consul_config:
  data_dir: "/var/lib/consul/"

  enable_syslog: true
  # "trace", "debug", "info", "warn", "err"
  log_level: "info"
  syslog_facility: "LOCAL5"

  rejoin_after_leave: true

  bind_addr: !unsafe '{{ GetInterfaceIP "eth0" }}'

  telemetry:
    disable_hostname: true
    prometheus_retention_time: "30s"

  server: false

Then, you can send this configuration to the host using the no_nice_json filter:

- name: copy consul config
  copy:
    content: "{{ consul_config | to_nice_json }}"
    dest: "/opt/consul/consul.json"
    validate: "consul validate -config-format=json %s"

When a variable is a map (like consul_services), each key in the map will be saved as a file with the value as the content.

For example, this map:

consul_services:
  consul:
    service:
      id: "consul-api"
      name: "consul-api"
      port: 8500
      tags:
        - "traefik.enable=true"
        - "traefik.http.routers.consul.entrypoints=https"
        - "traefik.http.routers.consul.rule=Host(`consul.example.com`)"
      meta:
        external-source: "consul"
      check:
        id: "consul-api-health"
        name: "consul-api-health"
        http: "http://localhost:8500/v1/agent/self"
        interval: "20s"
        timeout: "2s"

  telegraf:
    service:
      id: "telegraf-exporter"
      name: "telegraf-exporter"
      port: 9271
      meta:
        external-source: "consul"
      check:
        id: "telegraf-exporter-health"
        name: "telegraf-exporter-health"
        http: "http://localhost:9270"
        interval: "20s"
        timeout: "2s"

will create files consul.json and telegraf.json in the /opt/consul/service.d/ directory.

Any files not in the map will be deleted, helping to keep the state updated with the Ansible inventory.

Role Variables

Check defaults/ for more details and examples.

consul_version

  • Version to use

consul_dirs

  • A map of directories to create
  • Default:
consul_dir: "/opt/consul"
consul_dirs:
  main:
    path: "{{ consul_dir }}"
  configs:
    path: "{{ consul_dir }}/config.d"
  services:
    path: "{{ consul_dir }}/service.d"
  certs:
    path: "{{ consul_dir }}/certs"
    mode: "u=rwX,g=rX,o="
  scripts:
    path: "{{ consul_dir }}/script.d"
  logs:
    path: "/var/log/consul"
  data:
    path: "/var/lib/consul"
    mode: "u=rwX,g=rX,o="

consul_config

consul_configs

  • Map of configuration files to create in the config.d directory. They will restart on changes

consul_services

  • Map of service files to create in the service.d directory. They will reload on changes

consul_scripts

  • Map of scripts to create in the scripts.d directory

consul_user

  • Owner of the Consul process and files
  • Default: consul

consul_group

  • Group of the consul_user
  • Default: consul

consul_download_url

  • URL to download Consul from
  • Default: https://releases.hashicorp.com

consul_service

consul_unitfile

skip_handlers

  • Skip Consul restart/reload - useful when building images with packer
  • Default: false

Tags

  • config - Update Consul unit/service file and sync configuration files
  • services - Sync Consul services
  • scripts - Sync Consul scripts

Author

  • Anatoly Laskaris - nahsi
Installa
ansible-galaxy install nahsi.consul
Licenza
mit
Download
1.8k
Proprietario