• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Get Started With Ansible Playbooks

By Abhishek Ghosh May 22, 2016 6:23 pm Updated on May 22, 2016

Get Started With Ansible Playbooks

Advertisement

This is the second tutorial on Ansible. In the previous article of this series for getting started with Ansible, we said that we are the article before going to Playbook, Roles and Galaxy as they need separate guide. We suggest to read that article even if you have installed Ansible.

 

Get Started With Ansible Playbooks : How the Playbooks Works

 

Playbooks are the main components of Ansible from the aspect of deployment. In this Guide We Will Get Started With Ansible Playbooks With Very Easy to Understand Examples. As we have written before, Ansible Playbooks are YAML files which allows you to organize the configuration and management tasks. Each each of these playbooks contains a list of tasks known as play. Each playbook can be combined with other playbook. That is called Roles. Roles are reusable abstractions that contain a collection of features. Ansible has a community for users to share such kind of roles names Ansible Galaxy. Galaxy represent collections of ‘plays’, configuration policies which get applied to defined groups of hosts.

Get Started With Ansible Playbooks

Here is the official documentation on Playbooks :

Advertisement

---

Vim
1
http://docs.ansible.com/ansible/playbooks.html

This a typical structure of the Ansible Playbooks :

Structure of an Ansible Playbook
Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
+--site.yml    # master YAML playbook file. Contains info about rest of the playbook
+--hosts       # contains information about the hosts to be managed
+--group_vars/ # contains information like the hosts inventory file
|  |
|     +--group1
|     +--group2
|
+--host_vars/
|  |
|     +--hostname1
|     +--hostname2
+--roles/  # Defines how a server is supposed to perform
|     |
|     +--common/
|     |    
|     +--files/ # contains files which will be deployed to hosts without modification
|  |     +--templates/
|  |     +--tasks/
|  |     +--handlers/
|  |     +--vars/ # Stores variables in a YAML file with high priority
|  |     +--defaults/ # Includes information about default variables used by this role
|  |     +--meta/     # Meta contains files that describe environment
|  |
|     +--webservers/
|           …
|           …
|     +--applicationservers/
|           …
|           …
|     +--databaseservers/
|           …
|           …

 

Get Started With Ansible Playbooks : How to Write the Playbooks

 

YAML is a Syntax not be a programming language or script, it is done for easiness. In the previous guide, we used modules, not went to Playbook Mode. Take that, we have a playbook named site.yml, to execute that Playbook, we will run :

Vim
1
ansible-playbook -i hosts -k -K site.yml

How we will write a YAML file for making it Ansible Playbook? Ansible Playbook YAML files will starts with a list. Item in the list is a list of key/value pairs, this called hash (or a dictionary). So, we need to know how to write lists and dictionaries in YAML.
YAML files can begin with --- and end with ..... All the members of a list beginning at the same indentation level starting with one - :

Vim
1
2
3
4
5
6
7
8
---
 
# saved as tasks/myplay.yml
 
---
- hosts: all
  tasks:
    - shell: echo "hello world"

You can save it as myplay.yml and run this command to debug :

Vim
1
ansible-playbook --syntax-check --list-tasks -i inventory.ini myplay.yml

There is no reason to think that, 100% part of Playbooks are handwritten, there is automation for it too. This guide is like teaching to work with BASIC programming language.
You can install generator-ansible, but that is what we will not suggest to do if you are reading this type of guide for the first time.

 

Get Started With Ansible Playbooks : How to Execute the Playbooks

 

If the syntax is correct of the above myplay.yml then, they run :

Vim
1
ansible-playbook myplay.yml -i inventory.ini -u root

You can run on localhost :

Vim
1
ansible-playbook -i "localhost," -c local myplay.yml

Difficult command. Let us make it easy by using the default inventory file /etc/ansible/hosts/inventory.ini. Add an entry for localhost as given below:

/etc/ansible/hosts/inventory.ini
Vim
1
localhost ansible_connection=local

Now, if you run :

Vim
1
ansible-playbook myplay.yml

It will work on localhost.

In each of these Playbooks, we can include another YAML file :

Vim
1
2
3
4
5
- name: this is a play at the top level
  hosts: all
  remote_user: root
tasks:
- include: myplay.yml

After this basic guide, you really need to read the official documentation of Ansible on Playbooks. You should make yourself easy with the format and why the commands are written. It will take around a week to get easy. There are lot of examples on Galaxy and GitHub.

Tagged With ansible windows playbook , windows ansible playbooks , common ansible playbooks for windows , ansible_keep_files=1 windows , ansible-playbook windows , ansible-playbook for windows , ANSIBLE WINDOWS PLAYBOOKS , ansible windows playbook to check for symantec anti virus , ansible playbooks , ansible playbook windows
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Get Started With Ansible Playbooks

  • Ansible Ubuntu 16.04 1 Click Install WordPress, Nginx Playbook Tutorial

    Following This Tutorial, You Will Be Able to Create Own Ansible 1 Click Install WordPress Nginx Percona MySQL Playbook For Ubuntu 16.04.

  • Get Started With Ansible : Installation

    Here is How to Get Started With Ansible. Installation is on Local Computer to log into a Server From Installing Package or Restart Services.

  • How to Install Apache OpenWhisk on Ubuntu 18.04

    Here is How to Install Apache OpenWhisk on Ubuntu 18.04 to Create Own FaaS Environment. This is single VM/server deployment of OpenWhisk.

  • Ansible : The Tool For Cloud Orchestration

    Ansible is an Open Source Tool For Cloud Orchestration, General Configuration and Administration of Cloud Servers. Here is Basics on Ansible.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy