buluma.supervisor

Rola Ansible supervisor

Supervisor (menedżer stanu procesów) dla systemu Linux.

GitHub Wersja Zgłoszenia Prośby o ściągnięcie Pobrania
github Wersja Problemy Prośby o ściągnięcie Rola Ansible

Przykładowy Playbook

Przykład jest zaczerpnięty z molecule/default/converge.yml i jest testowany przy każdym wprowadzeniu zmian, prośbie o ściągnięcie i wersji.

---
- name: Połączenie
  hosts: all
  become: true

  environment:
    PATH: "/usr/local/bin:{{ ansible_env.PATH }}"

  vars:
    supervisor_user: root
    supervisor_password: fizzbuzz

  pre_tasks:
    - name: aktualizacja pamięci podręcznej apt (Debian).
      apt: update_cache=true cache_valid_time=600
      when: ansible_os_family == 'Debian'

    # Zainstaluj curl do celów testowych.
    - name: zainstaluj curl do celów testowych.
      package: name=curl state=present

    # Zainstaluj Apache do celów testowych.
    - block:
        - name: zainstaluj Apache (RedHat).
          package: name=httpd state=present
        - name: upewnij się, że Apache nie działa (RedHat).
          service: name=httpd state=stopped enabled=no
      when: ansible_os_family == 'RedHat'

    - block:
        - name: zainstaluj Apache (Debian).
          package: name=apache2 state=present
        - name: upewnij się, że Apache nie działa (Debian).
          service: name=apache2 state=stopped enabled=no
      when: ansible_os_family == 'Debian'

    - name: utwórz testowy plik HTML do załadowania.
      ansible.builtin.copy:
        content: "<html><head><title>Test</title></head><body>Test.</body></html>"
        dest: /var/www/html/index.html
        force: false
        group: root
        owner: root
        mode: 0644

    # Dodaj Apache do supervisor_programs.
    - name: ustaw polecenie startowe Apache (Debian).
      ansible.builtin.set_fact:
        apache_start_command: apache2ctl -DFOREGROUND
      when: ansible_os_family == 'Debian'

    - name: ustaw polecenie startowe Apache (RedHat).
      ansible.builtin.set_fact:
        apache_start_command: httpd -DFOREGROUND
      when: ansible_os_family == 'RedHat'

    - name: dodaj Apache do supervisor_programs.
      ansible.builtin.set_fact:
        supervisor_programs:
          - name: 'apache'
            command: "{{ apache_start_command }}"
            state: present
            configuration: |
              autostart=true
              autorestart=true
              startretries=1
              startsecs=1
              redirect_stderr=true
              stderr_logfile=/var/log/apache-err.log
              stdout_logfile=/var/log/apache-out.log
              user=root
              killasgroup=true
              stopasgroup=true

  roles:
    - role: buluma.supervisor

  tasks:
    - name: uruchom handlerów, aby supervisor uruchomił wszystko, co powinien.
      ansible.builtin.meta: flush_handlers

  post_tasks:
    - name: poczekaj na uruchomienie Apache (jeśli się uruchomi...).
      ansible.builtin.wait_for:
        port: 80
        delay: 2

    - name: sprawdź, czy Apache odpowiada na porcie 80.
      ansible.builtin.uri:
        url: http://127.0.0.1/
        method: GET
        status_code: 200

    - name: sprawdź, czy supervisorctl jest dostępny.
      command: supervisorctl --help
      args:
        warn: false
      changed_when: false

    - name: potwierdź, że supervisorctl działa przez domyślny gniazdko UNIX.
      community.general.supervisorctl:
        name: apache
        state: restarted
        username: "{{ supervisor_user }}"
        password: "{{ supervisor_password }}"
      changed_when: false

    - name: potwierdź, że supervisorctl działa z gniazdem UNIX
      command: supervisorctl status
      args:
        warn: false
      changed_when: false

Maszyna musi być przygotowana. W CI jest to realizowane za pomocą molecule/default/prepare.yml:

---
- name: Przygotowanie
  hosts: all
  gather_facts: no
  become: yes
  serial: 30%

  roles:
    - role: buluma.bootstrap
    - role: buluma.pip
    - role: buluma.core_dependencies

Zobacz także pełne wyjaśnienie i przykład dotyczące użycia tych ról.

Zmienne roli

Domyślne wartości dla zmiennych są ustawione w defaults/main.yml:

---
# Zainstaluj konkretną wersję Supervisora, ustawiając ją tutaj (np. '3.3.1').
supervisor_version: ''

# Wybierz, czy użyć skryptu init czy konfiguracji jednostki systemd do uruchomienia
# Supervisora po jego instalacji i/lub po uruchomieniu systemu.
supervisor_started: true
supervisor_enabled: true

supervisor_config_path: /etc/supervisor

# Lista `programów`, którymi będzie zarządzał Supervisor. Przykład skomentowany poniżej.
supervisor_programs: []
# - name: 'apache'
#   command: apache2ctl -c "ErrorLog /dev/stdout" -DFOREGROUND
#   state: present
#   configuration: |
#     autostart=true
#     autorestart=true
#     startretries=1
#     startsecs=1
#     redirect_stderr=true
#     stderr_logfile=/var/log/apache-err.log
#     stdout_logfile=/var/log/apache-out.log
#     user=root
#     killasgroup=true
#     stopasgroup=true

supervisor_nodaemon: false

supervisor_log_dir: /var/log/supervisor

supervisor_user: root
supervisor_password: 'moje_tajne_hasło'

supervisor_unix_http_server_enable: true
supervisor_unix_http_server_socket_path: /var/run/supervisor.sock
supervisor_unix_http_server_password_protect: true

supervisor_inet_http_server_enable: false
supervisor_inet_http_server_port: '*:9001'
supervisor_inet_http_server_password_protect: true

Wymagania

Stan używanych ról

Poniższe role są używane do przygotowania systemu. Możesz przygotować swój system w inny sposób.

Wymaganie GitHub Wersja
buluma.bootstrap Ansible Molecule Wersja
buluma.pip Ansible Molecule Wersja
buluma.core_dependencies Ansible Molecule Wersja

Kontekst

Ta rola jest częścią wielu kompatybilnych ról. Zobacz dokumentację tych ról tutaj po więcej informacji.

Oto przegląd związanych ról:

dependencies

Kompatybilność

Ta rola została przetestowana na tych obrazach kontenerów:

kontener tagi
EL 8
Debian wszystkie
Ubuntu wszystkie
Kali wszystkie

Minimalna wersja Ansible wymagana to 2.12, testy zostały przeprowadzone na:

  • wersji poprzedniej.
  • wersji bieżącej.
  • wersji deweloperskiej.

Jeśli znajdziesz problemy, zgłoś je w GitHub

Dziennik zmian

Historia roli

Licencja

Apache-2.0

Informacje o autorze

Shadow Walker

Zainstaluj
ansible-galaxy install buluma.supervisor
Licencja
apache-2.0
Pobrania
4k
Właściciel
DevOps Engineer