Ansible Playbooks vs Roles

后端 未结 5 1178
暖寄归人
暖寄归人 2021-01-29 20:38

According to the Ansible docs, a Playbook is:

...the basis for a really simple configuration management and multi-machine deployment system, unlike any that

5条回答
  •  日久生厌
    2021-01-29 21:07

    Playbook vs Role vs [databases] and similar entries in /etc/ansible/hosts

    Roles are a way to group tasks together into one container. You could have a role for setting up MySQL, another one for setting up Postfix etc.

    A playbook defines what is happening where. This is the place where you define the hosts (hostgroups, see below) and the roles which will be applied to those hosts.

    [databases] and the other entries in your inventory are hostgroups. Hostgroups define a set of hosts a play will run on.

    A play is a set of tasks or roles (or both) inside a playbook. In most cases (and examples) a playbook will contain only one single play. But you can have as many as you like. That means you could have a playbook which will run the role postfix on the hostgroup mail_servers and the role mysql on the hostgroup databases:

    - hosts: mail_servers
      roles:
        - postfix
    
    - hosts: databases
      roles:
        - mysql
    

    If Playbooks are defined inside of YAML files, then where are Roles defined?

    In Ansible pretty much everything is defined in YAML, that counts for roles and playbooks.

    Aside from the ansible.cfg living on the Ansible server, how do I add/configure Ansible with available Playbooks/Roles? For instance, when I run ansible-playbook someplaybook.yaml, how does Ansible know where to find that playbook?

    AFAIK you have to provide the path to the playbook when invoking ansible-playbook. So ansible-playbook someplaybook.yaml would expect someplaybook.yaml to be in you current directory. But you can provide the full path: ansible-playbook /path/to/someplaybook.yaml

提交回复
热议问题