50% found this document useful (4 votes)
2K views1 page

Ansible Cheat Sheet

This document provides an overview of Ansible including: - Ansible is an open source engine that automates deployment, orchestration, and other tools using a playbook and YAML files. - It connects to nodes through SSH and pushes small programs called modules without requiring an agent. - The document outlines types of machines in Ansible environments, how to install Ansible, common ad-hoc commands, and basics of playbooks including the structure of YAML files.

Uploaded by

Asawari Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
50% found this document useful (4 votes)
2K views1 page

Ansible Cheat Sheet

This document provides an overview of Ansible including: - Ansible is an open source engine that automates deployment, orchestration, and other tools using a playbook and YAML files. - It connects to nodes through SSH and pushes small programs called modules without requiring an agent. - The document outlines types of machines in Ansible environments, how to install Ansible, common ad-hoc commands, and basics of playbooks including the structure of YAML files.

Uploaded by

Asawari Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ANSIBLE Environment Setup Ad-hoc Commands Playbooks

CHEAT SHEET
Types of machines: • General syntax of ad-hoc command: • It is the place where all YAML files are stored and
• Control machine : manages other machines Command hostngroup module/options[arguments] executed. Acts like a to-do list
• Remote machine: controlled by other machines • YAML- yet another markup language
Multiple remote systems can be handled by one machine. • A playbook can have more than one plays. Plays map the
Ansible • Remote machine managing is done by ansible by default. FUNCTION COMMANDS instructions defined against a particular host
• Ansible doesn’t leave any software running on them. Therefore • Typically written in a text editor like notepad or
• It is an open source engine that automates deployment,
there is no need of an upgrade when moving to a newer Check connectivity of hosts #ansible <group> -m ping notepad++
orchestration, cloud provisioning and other tools.
version. Sample playbook/YAML file;
• It uses a playbook to describe jobs and uses YAML which is human
• Install it through apt, yumpkg, pip, OpenCSW name: install and configure DB
readable
• installing it through apt : Rebooting hosts #ansible <group> -a “/bin/reboot” hosts: testServer
• It is designed for multi- tier deployment. It is agentless and works by
$ sudo apt-get update become: yes
connecting nodes through ssh.
$ sudo apt-get install software-properties-common vars: oracle_db_port_value : 1521
Check host system’s info #ansible<group> -m steup | less
$ sudo apt-add-repository ppa: ansible/ansible $ sudo apt-get tasks:
How Does it Work? update
#ansible <group> -m copy -a
-name: Install the Oracle DB
$ sudo apt-get install ansible Transfering files yum: <code to install the DB>
• Run ansible version to make sure it was installed properly. “src=home/ansible dest=/tmo/home” -name: Ensure the installed service is enabled
• Connects nodes and pushes small programs called modules to them
service:
and are removed when they are done. #ansible<group> -m user -a “name=ansible
Create new user name: <your service name>
• The management node controls whole execution of the playbook. YAML password= <encrypted password>” • Tags of YAML:
• The inventory file provides the list of hosts where the modules need
• Name: name of the playbook
to be run. • YAML syntax is used to express ansible playbooks #ansible<group> -m user -a “name=ansible
Deleting user • Hosts: specifies the list of hosts. Tasks can be
• The management node does an ‘ssh’ connection and executes the • Key-value pair: state- absent” on the same machine or a different one.
modules and installs the software. Dictionary is represented in key value pair • Vars: defines the variables which you can use
Ex: james: Check if package is installed #ansible<group> -m yum -a “name=httpd
• Tasks: it is the list of action that needs to be
name: james john and update it state=latest” performed. A task is always linked to a module.
rollNo: 34
div: B Check if package is installed #ansible<group> -m yum -a “name=httpd
sex: male and dont update it state=present” Variables
• Representing lists:
• Each element has to be written in a new line with “-” Check if package is s #ansible<group> -m yum -a “name=httpd-
as the prefix specific version 1.8 state=latest” • Same as using variables in programming languages
• countries: Ex: - hosts : <your hosts>
- America Check if package is not #ansible <group> -m yum -a “name= httpd • tomcat_port : 8080
- Iceland installed state= absent • Here tomcat_port is assigned to 8080
• Lists inside the dictionary: • Keywords used:
• name: james john #ansible<group> -m service -a “name= • Block- ansible syntax to execute a block
Starting a service
• rollNo: 34 httpd state=”started” • Name- name of the block
• div: B • Action- the code that is to be executed
• sex: male #ansible<group> -m service -a “name= • Register- registers the output
Stopping a service
Troubleshooting • likes: httpd state=”stopped” • Always- states that below word will be run
- english • Msg- displays the message
• Boolean terms are also used in YAML #ansible<group> -m service -a “name= • Exception handling:
Restarting a service
httpd state=”restarted” • Similar to any other programming language
• Common strategies to debug playbooks are
• Keywords : rescue and always
• Debug and register
• Use verbosity (verbosity level)
Advantages of Ansible • The code is written in block
• It goes to the rescue phase and gets executed
• Playbook issues: • It is free and open source. Terms if the command in the block fails.
• Quoting • Agentless. No master client model. • Thereby block is the same as “try block “,
• Indentation
• System requirements. catch block is like “ rescue” and always
• Some drawbacks are: • Service/server- a process that provides service
• OS restrictions: is OS dependent so code on one OS will • Developed in python. • Machine - physical machine, Vm or a container
performs the same function as we know.
not work for another • Lightweight and quick deployment. • Target machine - end machine to be configured by ansible
• Once playbook is running, adding of hosts is not possible • Ansible uses YAML syntax in config files. • Task- an action FURTHERMORE:
• Error reporting is mediocre. • Large community base. • Playbook - location where YAMl files are written and executed DevOps Certification Training Course

You might also like