What is a Playbook?
Playbooks are essentially sets of instructions (plays) that you send to run on a single target or groups of targets (hosts). Think about the instructions you get for assembling an appliance or furniture. The manufacturer includes instructions so you can put the parts together in the correct order. When followed in order, the furniture looks like what was purchased.
Modules:
The Playbook we’re building will install a web server on a target RHEL/CentOS 7 host, then write an index.html file based on a template file that will reside with the final Playbook. You’ll be able to take the example Playbook and additional files from this blog and test it out for yourself. While going over the example Playbook, we’ll explain the modules that are used.
STEPS TO CREATE A PLAYBOOK:
Step 1: Using your favorite text editor (vim and nano are available on the control host) create a new file called name.yml.
Step 2: Enter the following play definition into name.yml.
Step 3: Next, add the first task. This task will use the ansible_facts module to gather facts about the device.
Step 4: Run the playbook using the ansible-playbook name.yml command.
Step 5: Running a playbook in verbose mode is a good option to validate the output from a task.
EXAMPLE:
vim name.yml
tasks:
– name: Add epel-release repo
yum:
name: epel-release
state: present
– name: Install nginx
yum:
name: nginx
state: present
TASK BY TRAINER:
Create a playbook packages.yml. Install the following packages.
1) httpd
2) Telnet
3) FTP