Ansible-A DevOps Tool
The term DevOps is a combination of terminology development and performance, intended to represent a collaborative or shared approach to tasks performed by company application development teams and IT operations teams. One of the DevOps tools is Ansible. Now let’s talk about Ansible in detail.
What is Ansible?
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows.
Basic commands of Ansible
Ø Verify connectivity of host: # ansible all-m -ping
Ø Rebooting host systems: #ansible all -a “/sbin/reboot”
Ø Creating a new user: # ansible all-m user -a “name=ansible password=<encrypted password>”
Ø User Deletion: # ansible all -m user -a “name=ansible state=absent”
To install Ansible on Windows using Cygwin, follow these steps:
1. Download the Cygwin installation file . It automatically installs the right version for your system.
2. Run the Cygwin installation file. On the starting screen of the installation wizard, click next to continue.
3. Select install from the internet as the download source and click next.
4. In the root directory field, specify where you want the application installed then click next.
5. In the local package directory field, select where you want to install your Cygwin packages, then click next.
6. Choose a direct connection. Click next to continue.
7. Choose one of the available mirrors to download the installation files, then click Next.
8. On the Select Packages screen, change the view option to full and type ‘ansible’ in the search bar.
Select both ansible and ansible doc by checking the boxes under Src? and click next to continue.
9. This screen lets you review the installation settings. To confirm and begin the install process, click on next.
10. The install wizard will download and install all the selected packages, including Ansible.
11. Once the installation is complete, select whether you want to add a Cygwin desktop and Start Menu icon, then click on Finish to close the wizard.
These were the steps to install ansible in your system may it be Windows or Linux. Let’s talk about the uses of ansible.
Uses of Ansible
The use cases of Ansible are:-
1. Infrastructure Provisioning
2. Configuration Management
3. IT automation
4. Continuous deployment
5. Application Development
6. Network Automation
7. Security Automation
8. Infrastructure Orchestration
Ansible Playbook
Coming to the practical use of this tool well if you want you can make your playbook using Ansible. For making a playbook you should be familiar with the following terminology:-
- Inventory- It is a list of hosts or groups of hosts. The default location for the inventory file is /etc/ansible//hosts. The ansible* commands will use a different host inventory file when they are used with the — inventory PATHNAME option, -i PATHNAME for short.
- Modules-Modules are the programs that perform the actual work of the tasks of a play. Core modules are the modules that come bundled with Ansible, There are over 400 core modules.
- Tasks- The goal of a play is to map a group of hosts to some well-defined roles, represented by things ansible calls tasks. At a basic level, a task is nothing more than a call to Ansible module.
Writing Nginx PLaybook
Ansible playbooks are written using the YAML Ain’t Markup Language
(YAML) language. So create a file with yml or yaml extension —
# vi nginx-install.yml
YAML files optionally begin with a three dash ( — -)
The next immediate line starts with a single dash(-). Name is optional here
hosts expect value like all or group.Do you want to become a root on target server uses become
name: <description>
hosts; all
become: true
what action do you want to perform? Specify under tasks
we are using this playbook to install Nginx.
what is the module to install Nginx?
tasks:
yum
name: nginx
state: latest
service:
name: nginx
start: started
Intelligent modules can be written in any language that can replace JSON (Ruby, Python, Bash, etc.). Inventory can also connect to any data source by typing a program that communicates with that data source and restores JSON. There are also various Python APIs to extend Ansible connection types (SSH is not the only possible transfer method), callbacks (how Ansible logs, etc.), and even add new server behaviour. In summary, using Ansible can greatly simplify your processes by allowing you to work with containers and make all work automatic! Not surprisingly, Ansible is very popular. And learning how to use Ansible will not only benefit you. In this article, we have provided you with an in-depth knowledge of what Ansible is.