Sobes.tech
Junior — Middle

Kuidas saab määratleda sihtkõikhostide nimekirja ülesannete täitmiseks Ansible'is?

sobes.tech AI

Vastus AI-lt

In Ansible, the list of target hosts (inventory) can be defined in several ways:

  1. Static inventory file — the most common method. It is a file in INI or YAML format, listing hosts and host groups.
[webservers]
web1.example.com
web2.example.com

[dbservers]
db1.example.com
  1. Dynamic inventory — a script or plugin that generates the list of hosts in real-time, for example, from a cloud provider (AWS, GCP).

  2. -i parameter in the command line — you can specify a particular inventory file or script when running ansible or ansible-playbook.

  3. Defining hosts in the playbook — in the hosts section of the playbook, you can specify a group or a specific host.

  4. Using the hosts variable in ad-hoc commands — for example, ansible webservers -m ping.

This way, the list of target hosts is defined through inventory files, dynamic sources, or directly in the playbook/commands.