• 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

This Article Has Been Shared 521 Times!

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

  • Cloud Computing in 2013 : The Way In Front

    Cloud Computing in 2013. What the major change that can be expected ? 2012 was the year for OpenStack. As it was an initiative started by NASA and The Rackspace Cloud and NASA has no commercial Cloud Computing Service, definitely the winner of 2012 from the point of progress towards a Free Software Mentality was […]

  • Cloud Computing Guide : Security and Firewall Policies

    Cloud Computing Guide on Security, Firewall and policies and how to operate in the cloud is important from a Provider to a SaaS user. Because there are Flaws.

  • GNU Privacy Guard (GPG) For Secure Cloud Computing

    GNU Privacy Guard (GPG) is used for code signing in Free Software. For secure Cloud Computing, GPG can be used for Emails and Messaging.

  • WordPress Auto Installation : HP Cloud + Cloud-Init Script

    We Will Use a Simple Cloud-Init Script For WordPress Auto Installation on HP Cloud’s OpenStack Client Infrastructure. Script is Provided Here.

  • Install OSSEC HIDS Security on Ubuntu 14.04 (HP Cloud)

    OSSEC is a Host-based Intrusion Detection System Free Software. Here is How to Install OSSEC HIDS Security on Ubuntu 14.04 on HP Cloud Server.

Additionally, 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

  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023
  • Difference Between Panel Light, COB Light, Track Light January 21, 2023
  • What is COB LED? How LED Chip On Board Works January 20, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Get Started With Ansible Playbooks," in The Customize Windows, May 22, 2016, January 27, 2023, https://thecustomizewindows.com/2016/05/get-started-with-ansible-playbooks/.

Source:The Customize Windows, JiMA.in

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT