[databases]
mydb01.example.org
mydb02.example.org


[mail_servers]
mymail01.example.org
mymail_dr.example.org

77780 次浏览

---
- 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

$ ansible-playbook someplaybook.yaml

$ ansible-playbook somedir/somedir/someplaybook.yaml

- hosts: mail_servers
roles:
- postfix


- hosts: databases
roles:
- mysql

- name: Some Action for two roles
hosts: localhost


vars_files:
- roles/dual_role/meta/main.yml


roles:
- dual_role/container-1
- dual_role/container-2

dual_role-playbook.yml
-- roles
-- dual_role
-- meta/main.yml
-- container-1
-- tasks/main.yml
-- templates/template.j2
-- container-2
-- tasks/main.yml
-- templates/template.j2

[web]
web1.example.com
web2.example.com