
上QQ阅读APP看书,第一时间看更新
Common
In the previous section of this chapter, we used the ansible-galaxy init command to create the common role. This creates several folders and files; before we start editing them, let's quickly discuss what each of them is used for:

It is really only the top level we are worried about; the main.yml files are just the default YAML files that are called for each part of the role:
- README.md: This is the file used to create any documentation about the role when the role is checked into a service such as GitHub. This file will be displayed along with the folder listing whenever someone browses to the common folder.
- default: This is where the default variables for the role are stored. These can be overridden by any variables with the same name called in the vars folder.
- files: This folder contains any static files we may wish to copy to the target hosts using the copy module.
- handlers: Handlers are tasks that are executed once a playbook has been executed; typically, handlers are used to restart services when a configuration file has changed.
- meta: This contains information about the role and is used if the role was to be published to Ansible Galaxy.
- tasks: This is where the bulk of the work happens.
- templates: This folder contains the Jinja2 templates used by the template module.
- tests: Used to store any tests for the module.
- vars: You can override any of the variables defined in the default folder using the variables defined here; variables defined here can also be overridden by any variables loaded from the group_vars folder and the top level of the playbook.
Let's make a start by adding some tasks.