Playbook

How to manage INFRA clusters using ansible playbooks, quick reference for common admin tasks.

There are three playbooks related to the INFRA module:

  • infra.yml: Initialize Pigsty infrastructure on infra nodes
  • infra-rm.yml: Remove infrastructure components from infra nodes
  • install.yml: Perform a complete one-time installation of Pigsty on the current node

infra.yml

The INFRA module playbook infra.yml initializes the infrastructure module on Infra nodes defined in the infra group of your config file.

This playbook performs the following tasks:

  • Configures directories and environment variables on Infra nodes
  • Downloads and creates a local software repository to accelerate subsequent installations (skipped if offline packages are used or if a local repository already exists)
  • Incorporates the current Infra node as a regular node managed by Pigsty
  • Deploys infrastructure components, including Prometheus, Grafana, Loki, Alertmanager, PushGateway, Blackbox Exporter, etc.

This playbook executes on the infra group by default:

  • Pigsty installs the INFRA module on the group named infra in the config file
  • During configure, Pigsty marks the current installation node as an Infra node and replaces the placeholder IP address 10.10.10.10 in the config template with the current node’s primary IP address
  • This node can initiate management tasks and hosts infrastructure components while functioning like any regular managed node

Playbook notes:

  • This is an idempotent playbook - repeated execution will overwrite infrastructure components on Infra nodes
    • Unless prometheus_clean is set to false, Prometheus time series metrics will be lost
    • Unless loki_clean is set to false, Loki log data will be lost
    • Unless grafana_clean is set to false, Grafana dashboards and configuration changes will be lost
  • When the local software repository /www/pigsty/repo_complete exists, this playbook skips downloading software from the internet
    • Complete execution takes approximately 1-3 minutes, depending on machine configuration and network conditions
    • Downloading software directly from the original upstream sources (without using offline packages) may take 5-10 minutes, depending on your network connection

Execution Demo

asciicast

Available Tasks

Here’s the list of available tasks in the infra.yml playbook:

#--------------------------------------------------------------#
# Tasks
#--------------------------------------------------------------#
# ca            : create self-signed CA on localhost files/pki
#   - ca_dir        : create CA directory
#   - ca_private    : generate ca private key: files/pki/ca/ca.key
#   - ca_cert       : signing ca cert: files/pki/ca/ca.crt
#
# id            : generate node identity
#
# repo          : bootstrap a local yum repo from internet or offline packages
#   - repo_dir      : create repo directory
#   - repo_check    : check repo exists
#   - repo_prepare  : use existing repo if exists
#   - repo_build    : build repo from upstream if not exists
#     - repo_upstream    : handle upstream repo files in /etc/yum.repos.d
#       - repo_remove    : remove existing repo file if repo_remove == true
#       - repo_add       : add upstream repo files to /etc/yum.repos.d
#     - repo_url_pkg     : download packages from internet defined by repo_url_packages
#     - repo_cache       : make upstream yum cache with yum makecache
#     - repo_boot_pkg    : install bootstrap pkg such as createrepo_c,yum-utils,...
#     - repo_pkg         : download packages & dependencies from upstream repo
#     - repo_create      : create a local yum repo with createrepo_c & modifyrepo_c
#     - repo_use         : add newly built repo into /etc/yum.repos.d
#   - repo_nginx    : launch a nginx for repo if no nginx is serving
#
# node/haproxy/docker/monitor : setup infra node as a common node (check node.yml)
#   - node_name, node_hosts, node_resolv, node_firewall, node_ca, node_repo, node_pkg
#   - node_feature, node_kernel, node_tune, node_sysctl, node_profile, node_ulimit
#   - node_data, node_admin, node_timezone, node_ntp, node_crontab, node_vip
#   - haproxy_install, haproxy_config, haproxy_launch, haproxy_reload
#   - docker_install, docker_admin, docker_config, docker_launch, docker_image
#   - haproxy_register, node_exporter, node_register, promtail
#
# infra         : setup infra components
#   - infra_env      : env_dir, env_pg, env_pgadmin, env_var
#   - infra_pkg      : infra_pkg_yum, infra_pkg_pip
#   - infra_user     : setup infra os user group
#   - infra_cert     : issue cert for infra components
#   - dns            : dns_config, dns_record, dns_launch
#   - nginx          : nginx_config, nginx_cert, nginx_static, nginx_launch, nginx_certbot, nginx_reload, nginx_exporter
#   - prometheus     : prometheus_clean, prometheus_dir, prometheus_config, prometheus_launch, prometheus_reload
#   - alertmanager   : alertmanager_config, alertmanager_launch
#   - pushgateway    : pushgateway_config, pushgateway_launch
#   - blackbox       : blackbox_config, blackbox_launch
#   - grafana        : grafana_clean, grafana_config, grafana_launch, grafana_provision
#   - loki           : loki clean, loki_dir, loki_config, loki_launch
#   - infra_register : register infra components to prometheus
#--------------------------------------------------------------#

infra-rm.yml

The INFRA module playbook infra-rm.yml removes Pigsty infrastructure from Infra nodes defined in the infra group of your config file.

Common subtasks include:

./infra-rm.yml               # Remove the INFRA module
./infra-rm.yml -t service    # Stop infrastructure services on INFRA
./infra-rm.yml -t data       # Remove retained data on INFRA
./infra-rm.yml -t package    # Uninstall packages installed on INFRA

install.yml

The INFRA module playbook install.yml performs a complete one-time installation of Pigsty on all nodes.

This playbook is described in more detail in Playbook: One-time Installation.





Last modified 2025-04-09: update infra doc (5591e0a)