nahsi.consul

Consul

安装、配置和维护Consul - HashiCorp 的服务网格。

角色哲学

为了避免将每个配置选项都复制为 Ansible 变量,Consul 配置以 yaml 格式存储在 Ansible 清单中:

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

然后使用 no_nice_json 过滤器复制到主机:

- name: 复制 consul 配置
  copy:
    内容: "{{ consul_config | to_nice_json }}"
    dest: "/opt/consul/consul.json"
    validate: "consul validate -config-format=json %s"

当变量是一个映射时(例如 consul_services),映射中的每个键将作为文件复制,值作为内容。

以下映射:

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"

将会在 /opt/consul/service.d/ 目录下生成 consul.jsontelegraf.json 文件。

在映射中不存在的文件将被删除,从而可以通过 Ansible 清单来维护状态。

角色变量

有关详细信息和示例,请查看defaults/

consul_version

  • 要使用的版本

consul_dirs

  • 要创建的目录映射
  • 默认:
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

  • 要在 config.d 目录中创建的配置文件映射。更改时重启

consul_services

  • 要在 service.d 目录中创建的服务文件映射。更改时重新加载

consul_scripts

  • 要在 scripts.d 目录中创建的脚本映射

consul_user

  • Consul 进程和文件的拥有者
  • 默认:consul

consul_group

  • consul_user 的组
  • 默认:consul

consul_download_url

  • 用于获取 Consul 归档的 URL
  • 默认:https://releases.hashicorp.com

consul_service

consul_unitfile

skip_handlers

  • 跳过 Consul 重启/重新加载 - 在使用打包器构建镜像时有用
  • 默认:false

标签

  • config - 更新 Consul 单元/服务文件并同步配置文件
  • services - 同步 Consul 服务
  • scripts - 同步 Consul 脚本

作者

  • Anatoly Laskaris - nahsi
安装
ansible-galaxy install nahsi.consul
许可证
mit
下载
1.8k