Ansible Playbooks vs Roles -
according ansible docs, playbook is:
...the basis simple configuration management , multi-machine deployment system, unlike exist, , 1 suited deploying complex applications.
and, again, according same docs, roles are:
...ways of automatically loading vars_files, tasks, , handlers based on known file structure. grouping content roles allows easy sharing of roles other users.
however distinction between these , different use cases not obvious me. instance, if configure /etc/ansible/hosts
file like:
[databases] mydb01.example.org mydb02.example.org [mail_servers] mymail01.example.org mymail_dr.example.org
...then "[databases]
" entry...a role? or name of playbook yaml file somewhere? or else?!?
if explain me differences on these, understanding of ansible enhance!
- playbook vs role vs
[databases]
, similar entries in/etc/ansible/hosts
- if playbooks defined inside of yaml files, roles defined?
- aside
ansible.cfg
living on ansible server, how add/configure ansible available playbooks/roles? instance, when runansible-playbook someplaybook.yaml
, how ansible know find playbook?
playbook vs role vs [databases] , similar entries in /etc/ansible/hosts
[databases]
single name group of hosts. allows reference multiple hosts single name.
role set of tasks , additional files configure host serve role.
playbook mapping between hosts , roles.
example documentation describes example project. contains 2 things:
- playbooks.
site.yml
,webservers.yml
,fooservers.yml
playbooks. - roles:
roles/common/
,roles/webservers/
contain definitions ofcommon
,webservers
roles accordingly.
inside playbook (webservers.yml
) have like:
--- - hosts: webservers <- group of hosts defined in /etc/ansible/hosts, databases , mail_servers in example question roles: <- list of roles assign these hosts - common - webservers
if playbooks defined inside of yaml files, roles defined?
they defined inside roles/*
directories. roles defined using yaml files, can contain resources of types (files/
, templates/
). according documentation role definition structured way:
- if roles/x/tasks/main.yml exists, tasks listed therein added play
- if roles/x/handlers/main.yml exists, handlers listed therein added play
- if roles/x/vars/main.yml exists, variables listed therein added play
- if roles/x/meta/main.yml exists, role dependencies listed therein added list of roles (1.3 , later)
- any copy tasks can reference files in roles/x/files/ without having path them relatively or absolutely
- any script tasks can reference scripts in roles/x/files/ without having path them relatively or absolutely
- any template tasks can reference files in roles/x/templates/ without having path them relatively or absolutely
- any include tasks can reference files in roles/x/tasks/ without having path them relatively or absolutely
the important file roles/x/tasks/main.yml
, here define tasks, executed, when role executed.
aside ansible.cfg living on ansible server, how add/configure ansible available playbooks/roles? instance, when run ansible-playbook someplaybook.yaml, how ansible know find playbook?
$ ansible-playbook someplaybook.yaml
will playbook inside current directory.
$ ansible-playbook somedir/somedir/someplaybook.yaml
will playbook inside somedir/somedir/
directory.
it's responsibility put project playbooks , roles on server. ansible has nothing that.
Comments
Post a Comment