The Playbook uses the YAML format to define one or more _ games _. A repertoire is an ordered set of tasks that are arranged in such a way as to automate a process, such as setting up a Web server or deploying an application into production.
In the PlayBook file, the game is defined as a YAML list. A typical game starts by determining which consoles are the target for that particular setting. This is done by the hosts directive.
Setting the hosts directive to all is a common choice, as you can restrict the goals of a game by running the Ansible-playbook command with the -l parameter at execution time. This allows you to run the same game manual on different servers or groups without having to change the game manual file every time.
First, create a new directory on your home folder where you can save your practice playbook. First, make sure you are in the Ubuntu user’s home directory. From there, create a directory called ansible-practice and navigate to it using the CD command.
cd ~
mkdir ansible-practice
cd ansible-practice
Copy the code
If you follow all the prerequisites, you should already have a working checklist file. You can now copy that file to your new directory, Ansible-practice. For example, if you created your test inventory file in the Ansible directory in your home folder, you can copy that file to the new directory.
cp ~/ansible/inventory ~/ansible-practice/inventory
Copy the code
Next, create a new game manual file.
nano playbook-01.yml
Copy the code
The playBook below defines a game for a given list of all consoles. It contains a task to print debugging information.
Note: We’ll learn more about tasks in the next section of this series.
Add the following to your Playbook-01.yml file.
~/ansible-practice/playbook-01.yml
---
- hosts: all
tasks:
- name: Print message
debug:
msg: Hello Ansible World
Copy the code
When finished, save and close the file. If you are using nano, you can confirm this by typing CTRL+X, then Y and ENTER.
To try out this game rule on the server you set up in the manifest file, run ansible-Playbook with the same connection parameters you used when running connection tests in this series. Here, we’ll use a directory file named Inventory and Sammy user to connect to the remote server, but be sure to change these details to fit your own directory file and admin user.
ansible-playbook -i inventory playbook-01.yml -u sammy
Copy the code
You’ll see something like this output.
OutputPLAY [all] *********************************************************************************** TASK [Gathering Facts] *********************************************************************** ok: [203.0.113.10] TASK [Update apt cache] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ok: [203.0.113.10] = > {" MSG ": "Hello Ansible World" } PLAY RECAP *********************************************************************************** 203.0.113.10: OK =2 changed=0 UNREachable =0 failed=0 skipped=0 rescued=0 ignored=0Copy the code
You may have noticed that although you only defined one mission in the game manual, you listed two missions in the game output. At the start of each game, Ansible defaults to perform an additional task, gathering information about the remote node (called _ fact _). Because facts can be used on the PlayBook to better customize the behavior of the task, the fact gathering task must occur before any other task can be performed.
We’ll learn more about Ansible facts in a later section of this series.