Sobes.tech
Junior — Middle

How can the host be identified in an inventory file with a YAML extension for automatic loading?

sobes.tech AI

Answer from AI

In the inventory file with a YAML extension for Ansible, hosts are defined in the hosts section or simply as top-level keys. For example:

all:
  hosts:
    webserver1:
      ansible_host: 192.168.1.10
    dbserver1:
      ansible_host: 192.168.1.20

Here, webserver1 and dbserver1 are host names that Ansible will automatically load from the inventory. You can also use host groups for easier organization.

Thus, to define a host, you need to specify its name under the hosts key or in the corresponding group in the YAML inventory file.