Are you finding difficulty in remembering all the commands that you need in order to work with Ansible?
Guys don’t worry if you are a beginner and have no idea about how Ansible works, this Ansible cheat sheet will give you a quick reference of the basics that you must know to get started.
While at Intellipaat, we support our learners with a handy reference, that’s the reason we have created this Cheat sheet.
This cheat sheet is designed for the one who has already started learning about Ansible but needs a handy reference sheet.
Learn DevOps in 16 hrs from experts
It is an open source engine that automates deployment, orchestration, cloud provisioning and other tools. It uses a playbook to describe jobs and uses YAML which is human readable and is designed for multi- tier deployment. It is agentless and works by connecting nodes through SSH.
Ansible does its work by connecting the nodes and pushes small programs called modules to them and are removed when they are done.
If we conclude the above diagram:
Before moving forward and working on commands, let’s understand few aspects for environment setup and then we will setup the Ansible Machine.
Let’s discuss the types of machine when we are talking of deployment.
Types of machines:
Multiple remote machines can be handled by one machine, and the remote machine managing is done through ansible by default.
Run Ansible version command to make sure it was installed properly.
Before looking into important commands of Ansible, first let’s understands its terms
YAML syntax is used to express the ansible playbooks
Here are some basic concepts of YAML:
Dictionary is represented in key value pair
Each element has to be written in a new line with “-” as the prefix
Lists inside the dictionary:
Boolean terms are also used in YAML
An Ad-hoc commands are something that you might type in order to do something really quick, but you don’t want to save them for late, which means those commands need not to be performed later.
General syntax of ad-hoc command:
|Check connectivity of hosts||#ansible <group> -m ping|
|Rebooting hosts||#ansible <group> -a “/bin/reboot”|
|Check host system’s info||#ansible<group> -m steup | less|
|Transfering files||#ansible <group> -m copy -a “src=home/ansible dest=/tmo/home”|
|Create new user||#ansible<group> -m user -a “name=ansible password= <encrypted password>”|
|Deleting user||#ansible<group> -m user -a “name=ansible state- absent”|
|Check if package is installed and update it||#ansible<group> -m yum -a “name=httpd state=latest”|
|Check if package is installed and don’t want to update it||#ansible<group> -m yum -a “name=httpd state=present”|
|Check if package is s specific version||#ansible<group> -m yum -a “name=httpd-1.8 state=latest”|
|Check if package is not installed||#ansible <group> -m yum -a “name= httpd state= absent|
|Starting a service||#ansible<group> -m service -a “name= httpd state=”started”|
|Stopping a service||#ansible<group> -m service -a “name= httpd state=”stopped”|
|Restarting a service||#ansible<group> -m service -a “name= httpd state=”restarted”|
It is the place where all YAML files are stored and executed. Acts like a to-do list.
Sample playbook/YAML file:
Some general tags of YAML:
It is as similar to using variables in programming languages
Here tomcat port is the variable and it has been assigned to Port 8080
Important Keywords used:
The most common strategies to debugging the playbooks are
Some of its drawbacks are:
We have covered all the basics of Ansible in this cheat sheet. If you want to start learning DevOps in depth then check out the DevOps Certification by Intellipaat.
Not only will you get to learn and implement Ansible with a step by step guidance and support from us, but you will also get to learn other important topics in DevOps such as Docker, Git/GitHub, Chef, Jenkins, Puppet, Selenium, Nagios and many more. You will also get 24*7 technical support to help you with any and all of your queries, from the experts in the respective technologies here at intellipaat throughout the certification period. So, why wait? Check out the training program and enroll today!Previous Next
Download Interview Questions asked by top MNCs in 2019?