An Ansible playbook is a blueprint of automation tasks performed with limited or no human involvement. Ansible playbooks are run on a set, group, or classification of hosts, which together make up an Ansible inventory. Figure 4 shows a basic playbook.
Figure 4. A basic playbook
A playbook usually includes the following keywords, as shown in Figure 4.
- name—An identifier for the playbook that, ideally, gives a good indication of what the playbook will accomplish. A name can be dynamic and include variables, as in the example, so at run time it changes according to the values the playbook is run with.
- hosts—The host on which the playbook is run. Because Dell playbooks use REST APIs, hosts is usually set to localhost and the Ansible server runs the REST calls.
- connection—The connection method, which is usually set to local because the Ansible server makes REST calls.
- info—An optional keyword that is not necessary for running Dell modules. Setting info to no reduces run time slightly. Gathering information about the configuration of the local host is unnecessary because this information will not be used in any PowerMax playbook.
- vars_files—An optional keyword detailing any variable files that provide information for the playbook to run.
- Vars—Any variables that the playbook needs to run. This keyword is optional because variables can also be passed in at run time on the command line.
- input—A special keyword known as an anchor, which is used to reference multiple values with a single variable referenced by &uni_connection_vars. Figure 4 shows credentials and connection variables shorthanded with this technique. Subsequent tasks can refer to the grouped variables using the <<:*uni_connection_vars anchor.
- Collections—Collections to be imported. Using this keyword to import the dellemc.PowerMax namespace tells the playbook where to look for PowerMax modules.
Note: When the collections keyword is specified in a playbook, it is not necessary to include the fully qualified canonical name (FQCN) for a module, such as dellemc.PowerMax.storagegroup. The name can be shortened to storagegroup. Use the FQCN for easy linking to the module documentation and to avoid conflicts with other collections that might have the same module name.
Best Practice: Because the YAML file works like a scripting language, you can use comment lines as often as needed. These lines are ignored during parsing. Comment lines start with the # symbol followed by some text. You can use them to explain playbook sections so that they are easier for others to read.