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:
- 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
-
Dynamic inventory — a script or plugin that generates the list of hosts in real-time, for example, from a cloud provider (AWS, GCP).
-
-iparameter in the command line — you can specify a particular inventory file or script when running ansible or ansible-playbook. -
Defining hosts in the playbook — in the
hostssection of the playbook, you can specify a group or a specific host. -
Using the
hostsvariable 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.