Junior
How to declare a host in inventory if we have a YAML file?
sobes.tech AI
Answer from AI
# Example YAML inventory for Ansible
all:
hosts:
web01:
ansible_host: 192.168.1.10
user: admin
db01:
ansible_host: 192.168.1.20
user: dbuser
children:
webservers:
hosts:
web01:
databases:
hosts:
db01:
In the YAML file, hosts are declared under the hosts key within the respective groups (e.g., all, webservers, databases). Each host is represented as a key with nested parameters such as ansible_host (DNS name or IP address) and user (user for connection). Groups are declared under the children key, and their hosts list the hosts belonging to them.