igor_nikiforov.etcd

Rola Ansible: etcd

Ta rola konfiguruje etcd i etcdctl na docelowym hoście. Obsługuje wszystkie opcje konfiguracyjne etcd i stara się być jak najbardziej elastyczna.

Wymagania

Ta rola została opracowana i przetestowana z następującymi wersjami Ansible:

Nazwa Wersja
ansible >= 2.9.13
ansible-base >= 2.10.1

Inne wersje Ansible nie były testowane, ale prawdopodobnie będą działać.

Instalacja

Użyj ansible-galaxy install igor_nikiforov.etcd, aby zainstalować najnowszą stabilną wersję roli.

Możesz również zainstalować rolę z pliku wymagań używając ansible-galaxy install -r requirements.yml:

# requirements.yml
---
roles:
  - name: igor_nikiforov.etcd
    version: v1.0.0

Platformy

Nazwa Wersja
Debian buster, bullseye
Ubuntu focal, jammy
CentOS 7.4+, stream8
RedHat 7.4+, 8

Inne dystrybucje systemów operacyjnych nie były testowane, ale prawdopodobnie będą działać. W przypadku problemów zgłoś prośbę o zmianę!

Zmienne

Nazwa Opis Domyślna
etcd_version Wersja etcd do zainstalowania 3.4.13
etcd_user Użytkownik etcd etcd
etcd_group Grupa etcd etcd
etcd_config Lista parametrów konfiguracyjnych etcd. {}
etcd_service_enabled Czy usługa powinna uruchamiać się przy starcie. True
etcd_service_state Stan usługi dla etcd. started
etcdctl_output_format Format wyjściowy używany w etcdctl. table

Użycie

Rola obsługuje wszystkie parametry konfiguracyjne etcd, które można przekazać za pomocą zmiennej etcd_config. Przykład formatu konfiguracji YAML można znaleźć w oficjalnym repozytorium etcd, a wszystkie dostępne flagi z opisem w oficjalnej dokumentacji etcd.

etcd obsługuje dwie główne metody budowania klastra:

  1. Statyczna.

    Po wykonaniu playbooka należy ręcznie dodać każdego członka z jednego z hostów za pomocą polecenia etcdctl member add. Zakłada to, że zrobisz to manualnie lub zautomatyzujesz w osobnym zadaniu Ansible.

  2. Odkrywanie DNS.

    Głównym wymogiem jest przygotowanie rekordów SRV i A w twojej lokalnej strefie DNS. Należy dokładnie sprawdzić wymagania dotyczące rekordów DNS, które powinny być utworzone wcześniej. Jeśli wszystko zostało poprawnie utworzone, następujące właściwości związane z odkrywaniem DNS należy dodać do etcd_config:

    etcd_config:
      discovery-srv: "company.local"
      discovery-srv-name: "dev" # opcjonalne
    

    Po wykonaniu playbooka klaster etcd zostanie automatycznie utworzony. Zdecydowanie zaleca się korzystanie z tej metody w produkcji.

Ważne:

  • Nie zapomnij zmienić etcd_config.initial-cluster-state z new na existing w playbooku po pierwszym wykonaniu.
  • Użyj serial: 1 w swoim playbooku po zbudowaniu klastra, aby bezpiecznie go zaktualizować w przypadku zmiany konfiguracji. Więcej informacji tutaj.

Przykłady

Statyczna

# playbook.yml
---
- hosts: all
  become: True
  gather_facts: False

  pre_tasks:
    - wait_for_connection: {timeout: 300}
    - setup:

  tasks:
    - name: Zainstaluj etcd
      import_role:
        name: etcd
      vars:
        etcd_version: "3.4.13"
        etcd_config:
          name: "{{ ansible_facts.hostname }}"
          data-dir: "/var/lib/etcd/data"
          wal-dir: "/var/lib/etcd/wal"
          initial-advertise-peer-urls: "https://{{ ansible_facts.fqdn }}:2380"
          initial-cluster-token: "token"
          initial-cluster-state: "new"
          advertise-client-urls: "https://{{ ansible_facts.fqdn }}:2379"
          listen-client-urls: "https://{{ ansible_default_ipv4.address }}:2379,https://127.0.0.1:2379"
          listen-peer-urls: "https://{{ ansible_default_ipv4.address }}:2380"
          client-transport-security:
            trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
            cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
            key-file: "{{ etcd_conf_dir }}/certs/server.key"
          peer-transport-security:
            trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
            cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
            key-file: "{{ etcd_conf_dir }}/certs/server.key"
          log-level: "debug"
          logger: "zap"

Odkrywanie DNS

# playbook.yml
---
- hosts: all
  become: True
  gather_facts: False

  pre_tasks:
    - wait_for_connection: {timeout: 300}
    - setup:

  tasks:
    - name: Zainstaluj etcd
      import_role:
        name: etcd
      vars:
        etcd_version: "3.4.13"
        etcd_config:
          name: "{{ ansible_facts.hostname }}"
          data-dir: "/var/lib/etcd/data"
          wal-dir: "/var/lib/etcd/wal"
          discovery-srv: "company.local"
          initial-advertise-peer-urls: "https://{{ ansible_facts.fqdn }}:2380"
          initial-cluster-token: "token"
          initial-cluster-state: "new"
          advertise-client-urls: "https://{{ ansible_facts.fqdn }}:2379"
          listen-client-urls: "https://{{ ansible_default_ipv4.address }}:2379,https://127.0.0.1:2379"
          listen-peer-urls: "https://{{ ansible_default_ipv4.address }}:2380"
          client-transport-security:
            trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
            cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
            key-file: "{{ etcd_conf_dir }}/certs/server.key"
          peer-transport-security:
            trusted-ca-file: "{{ etcd_conf_dir }}/certs/ca.crt"
            cert-file: "{{ etcd_conf_dir }}/certs/server.crt"
            key-file: "{{ etcd_conf_dir }}/certs/server.key"
          log-level: "debug"
          logger: "zap"

Licencja

MIT

Informacje o autorze

Igor Nikiforov

O projekcie

Install and configures etcd key-value store

Zainstaluj
ansible-galaxy install igor_nikiforov.etcd
Licencja
mit
Pobrania
1.7M
Właściciel