---
#--------------------------------------------------------------#
# Infra Directories                                  [infra_dir]
#--------------------------------------------------------------#
# Create all infra directories with proper ownership and permissions
# FHS:
# /www   -> /data/nginx    # soft link: nginx_home -> nginx_data
# /infra -> /data/infra    # soft link for convenience
# /data/nginx/             # nginx data root (nginx_data)
#  ^--- pigsty/            # local software repo
#  ^--- acme/              # ACME cert challenge
#  ^--- logs/              # nginx logs
#  ^--- ...
# /data/infra/             # infra data root
#  ^--- metrics/           # VictoriaMetrics data
#  ^--- logs/              # VictoriaLogs data
#  ^--- traces/            # VictoriaTraces data
#  ^--- alertmgr/          # AlertManager data
#
#  ^--- prometheus.yml     # VictoriaMetrics config
#  ^--- targets/           # FileSD targets
#  ^--- rules/             # Alert and recording rules
#  ^--- bin/               # Utility scripts
#
#  ^--- dashboards/        # Grafana dashboards definitions
#  ^--- datasources/       # Grafana datasource definitions
#--------------------------------------------------------------#

#--------------------------------------------------------------#
# Create infra data directories                 [infra_dir_data]
#--------------------------------------------------------------#
# main data directory, mode=0771 allows services like dnsmasq to traverse
- name: create infra data directories
  tags: [ infra_dir, infra_dir_data ]
  file: path={{ infra_data }} state=directory owner=root group=infra mode='0771'

#--------------------------------------------------------------#
# Create infra data directories                 [infra_dir_link]
#--------------------------------------------------------------#
- name: create infra soft link
  tags: [ infra_dir, infra_dir_link ]
  file: src=/data/infra dest=/infra state=link

#--------------------------------------------------------------#
# Create infra data directories               [infra_dir_create]
#--------------------------------------------------------------#
- name: create infra data directories
  tags: [ infra_dir, infra_dir_create ]
  file: path={{ item.path }} state={{ item.state|default('directory') }} owner={{ item.owner|default(root) }} group={{ item.group|default('infra') }} mode={{ item.mode|default('0750') }}
  with_items:
    - { path: /infra/pgadmin ,owner: 5050 ,group: 5050  ,mode: '0700' }
    - { path: /infra/alertmgr        ,owner: prometheus ,mode: '0700' }
    - { path: /infra/conf            ,owner: root     }
    - { path: /infra/tmp             ,owner: root     }
    - { path: /infra/datasources     ,owner: root     }
    - { path: /infra/dashboards      ,owner: grafana  }
    - { path: /infra/metrics         ,owner: victoria }
    - { path: /infra/logs            ,owner: victoria }
    - { path: /infra/traces          ,owner: victoria }
    - { path: /infra/rules           ,owner: victoria }
    - { path: /infra/bin             ,owner: victoria }
    - { path: /infra/targets/        ,owner: victoria }
    - { path: /infra/targets/node    ,owner: victoria }
    - { path: /infra/targets/ping    ,owner: victoria }
    - { path: /infra/targets/etcd    ,owner: victoria }
    - { path: /infra/targets/infra   ,owner: victoria }
    - { path: /infra/targets/pgsql   ,owner: victoria }
    - { path: /infra/targets/pgrds   ,owner: victoria }
    - { path: /infra/targets/redis   ,owner: victoria }
    - { path: /infra/targets/minio   ,owner: victoria }
    - { path: /infra/targets/mongo   ,owner: victoria }
    - { path: /infra/targets/juice   ,owner: victoria }
    - { path: /infra/targets/mysql   ,owner: victoria }
    - { path: /infra/targets/kafka   ,owner: victoria }
    - { path: /infra/targets/docker  ,owner: victoria }
    - { path: /infra/targets/patroni ,owner: victoria }

...
