Playbook vs Role vs [databases] and similar entries in / etc / ansible / hosts
[databases] is one name for a group of hosts. It allows you to refer to multiple hosts by the same name.
A role is a set of tasks and additional files for configuring a host to perform a specific role.
Playbook is a mapping between hosts and roles.
An example from the documentation describes an example project. It contains two things:
- Playbooks
site.yml , webservers.yml , fooservers.yml are players. - Roles:
roles/common/ and roles/webservers/ contain definitions of common and webservers roles, respectively.
Inside the playbook ( webservers.yml ) you have something like:
--- - hosts: webservers <- this group of hosts defined in /etc/ansible/hosts, databases and mail_servers in example from your question roles: <- this is list of roles to assign to these hosts - common - webservers
If books are defined in YAML files, then where are the roles defined?
They are defined inside the roles/* directories. Roles are defined mainly using YAML files, but can also contain resources of any type ( files/ , templates/ ). According to the documentation, the definition of a role is structured as follows:
- If the /x/tasks/main.yml roles exist, the tasks listed in it will be added to the game.
- If the /x/handlers/main.yml roles exist, the handlers listed in it will be added to the game,
- If the /x/vars/main.yml roles exist, the variables listed in it will be added to the game.
- If /x/meta/main.yml roles exist, any role dependencies listed in it will be added to the role list (1.3 and later).
- Any copy tasks can refer to files in the roles / x / files / without the need to relate them relatively or absolutely
- Any script tasks can refer to scripts in the roles / x / files / without having to relate them relatively or absolutely
- Any tasks of the template can refer to files in the roles / x / templates / without the need to relate them relatively or absolutely
- Any included tasks can refer to files in the roles / x / tasks / without the need to relate them relatively or absolutely
The most important file is roles/x/tasks/main.yml , here you define the tasks that will be executed when the role is executed.
Besides ansible.cfg, which lives on Ansible server, how can I add / configure Ansible with available Playbooks / Roles? For example, when I run the boot file someplaybook.yaml, how does Ansible know where to find this book?
$ ansible-playbook someplaybook.yaml
Will look for a tutorial in the current directory.
$ ansible-playbook somedir/somedir/someplaybook.yaml
Look at the playbook inside the somedir/somedir/ directory.
It is your responsibility to put your project with all the game books and roles on the server. Ansible has nothing to do with it.