Files
SecondBrain/01 Library/02 DevOps/Ansible/Inventory - Ansible.md
T
2026-04-17 11:28:35 +03:00

1.7 KiB

status, type, tags, updated, title, created
status type tags updated title created
stable concept
devops
2026-02-27 Inventory - Ansible 2025-12-17

Inventory - Ansible

Особенности Ansible:

  1. Подключение по SSH
  2. Agentless - нет программ на клиентах

Структура файла hosts.ini

192.168.0.1
192.168.0.2

[web] # группа серверов
192.168.0.3
192.168.0.4

Можно использовать псевдонимы, вместо ip

app ansible_host=ip_server1
db ansible_host=ip_server2
web ansible_host=ip_server3

Другие полезные параметры inventory:

  • ansible_connection: ssh/winrm/local/docker - тип подключения к серверу
  • ansible_port: 22/5986 - порт подключения
  • ansible_user: root - логин для входа по ssh (или др.)
  • ansible_ssh_pass: password или ansible_password: password - пароль для входа по ssh.

Группы для объединения групп:

[mail_internal]
mail1.serv

[mail_external]
mail2.serv

[mail_all:children]
mail_internal
mail_external

Помимо ini-формата, можно использовать YAML-файлы:

all:
  children:
    webservers:
      hosts:
        web1.example.com:
          ansible_host: 192.168.1.10
          ansible_user: admin
        web2.example.com:
          ansible_host: 192.168.1.11
      vars:
        ansible_port: 22
        ansible_python_interpreter: /usr/bin/python3

    databases:
      hosts:
        db1.example.com:
        db2.example.com:

    production:
      children:
        webservers:
        databases: