Рубрики
ansible

ansible invertory / файл host.txt

Файл пример:

Можно записывать так просто перечислить ip адреса
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5

Можно записывать имена серверов
name1
name2
name3
name4
name5

!!! Все хосты входят в группы
!!! Все хосты входят в группу all
!!! Все хосты которым не назначена группа, входят в группу ungrouped и all

[staging_DB]
192.168.0.10
192.168.0.11

[staging_WEB]
192.168.0.20
192.168.0.21

[staging_APP]
192.168.0.30
192.168.0.31

[staging_ALL:children]
staging_DB
staging_WEB
staging_APP

[prod_DB]
10.10.10.1
[prod_WEB]
10.10.10.2
[prod_APP]
10.10.10.3

[prod_ALL:children]
prod_DB
prod_WEB
prod_APP

[DB_ALL:children]
staging_DB
prod_DB

[APP_ALL:children]
staging_APP
prod_APP

[APP_ALL:vars]
message=Hello

[staging_servers]
linuxX ansible_host=192.168.15.142 ansible_user=USERNAME7  ansible_ssh_private_key_file=/home/USERNAME7/.ssh/id_rsa
 
[prod_servers]
linux1 ansible_host=192.168.15.145
linux2 ansible_host=192.168.15.146

[prod_servers:vars]
ansible_user=USERNAME1
ansible_ssh_private_key_file=/home/USERNAME1/.ssh/nameSSHKey1.pem 


[windows_servers]
windows1 ansible_host=192.168.15.147
windows2 ansible_host=192.168.15.146
 
[windows_servers:vars]
ansible_user = admin
ansible_password = PASSWORD@123 !!! можно убрать пароль из конфига, а при запуске команды ansible писать --ask-pass
ansible_port = 5986
ansible_connection = winrm
ansible_winrm_serv_cert_validation = ignore

ДОП

ansible-invertory --list - покажет все хосты и какие переменные к ним относятся
ansible-inventory --graph - - покажет все хосты и какие группы в виде дерева