Blog 8
Blog 8
What is an Ansible Playbook?
Remember Dockerfiles? Ansible Playbooks are the same, but different… Essentially you are placing coordinated instructions inside a YAML file, then let Ansible do the rest of the hard work. Previously, with server configuration management, in order to make a change to a group of servers, each server had to be configured indivudally. Even if they are part of the same group. There wasn’t a good efficient way to push these configurations to a group of servers. Ansible and its playbooks have made it possible to do so. Allowing the system administrator to focus more on other tasks.
Ansible playbooks can be as simple as running a series of commands on different servers in a sequence and rebooting in a specified sequence. They can also be used for more complex tasks such as deploying many virtual machines in a private cloud strucutre, or configuring web and database servers, load balancing, etc.
Ansible Playbook Syntax
All playbooks are written in the YAML, Yet Another Markup Language, format. A playbook is a set of “plays”. Within each set of “plays”, are “tasks”. Within each task a certain Ansible module is called upon. The task is the instruction that is being fed to Ansible. Pretty simple. However the most difficult part for me is betting used to the spacing of each line of code.
Running the Playbooks
The most used command with playbooks:
ansible-playbook insertnameofplaybook.yml
Example of My Ansible Playbook
In this example, I’m just installing packages to local host.
**—
-
hosts: 127.0.0.1 connection: local
tasks:
- name: Install Required Packages For Lab3 apt: name: - git - curl - mysql-client - apache2 - php - nano - libapache2-mod-php - php-mysql - php7.2-cli - php7.2-curl - php7.2-gd - php7.2-mbstring - php7.2-mysql - php7.2-xml - php-xml state: present**
It’s pretty simple, the difficult part is trying to understand what each module does. The module in this example is just installing different tools and packages. This same playbook can be used and applied to many servers.