Ansible Tutorial for Beginners – The BEST Step-By-Step Guide
Last updated on 21st Jun 2020, Blog, Tutorials
What is Ansible?
Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they have to do everything manually.
Automation simplifies complex tasks, not just making developers’ jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency. And Ansible, as noted above, is rapidly rising to the top in the world of automation tools. Let’s look at some of the reasons for Ansible’s popularity.Now that we have seen what is Ansible, let us find out the various advantages of Ansible.
The term “ansible” was coined by Ursula K. Le Guin in her 1966 novel Rocannon’s World,and refers to fictional instantaneous communication systems.Rocannon’s World is a science fiction novel by American writer Ursula K. Le Guin, her literary debut. It was published in 1966 as an Ace Double, along with Avram Davidson’s The Kar-Chee Reign, following the tête-bêche format. Though it is one of Le Guin’s many works set in the universe of the technological Hainish Cycle, the story itself has many elements of heroic fantasy. The hero Gaveral Rocannon encounters lords who live in castles and wield swords, and other races much like fairies and gnomes, in his travels on a backward planet.
The Ansible tool was developed by Michael DeHaan, the author of the provisioning server application Cobbler and co-author of the Fedora Unified Network Controller (Func) framework for remote administration.Ansible, Inc. (originally AnsibleWorks, Inc.) was the company set up to commercially support and sponsor Ansible.Red Hat acquired Ansible in October 2015.
Ansible is included as part of the Fedora distribution of Linux, owned by Red Hat, and is also available for Red Hat Enterprise Linux, CentOS, openSUSE, SUSE Linux Enterprise, Debian, Ubuntu, Scientific Linux, and Oracle Linux via Extra Packages for Enterprise Linux (EPEL), as well as for other operating systems.
Error: Contact form not found.
Unlike most configuration-management software, Ansible does not require a single controlling machine where orchestration begins Ansible works against multiple systems in your infrastructure by selecting portions of Ansible’s inventory, stored as edit-able, version-able ASCII text files. Not only is this inventory configurable, but you can also use multiple inventory files at the same time and pull inventory from dynamic or cloud sources or different formats (YAML, INI, etc). Any machine with Ansible utilities installed can leverage a set of files/directories to orchestrate other nodes. The absence of a central-server requirement greatly simplifies disaster-recovery planning. Nodes are managed by this controlling machine – typically over SSH. The controlling machine describes the location of nodes through its inventory. Sensitive data can be stored in encrypted files using Ansible Vault since 2014. In contrast with other popular configuration-management software — such as Chef, Puppet, and CFEngine — Ansible uses an agentless architecture, with Ansible software not normally running or even installed on the controlled node. Instead, Ansible orchestrates a node by installing and running modules on the node temporarily via SSH. For the duration of an orchestration task, a process running the module communicates with the controlling machine with a JSON-based protocol via its standard input and output. When Ansible is not managing a node, it does not consume resources on the node because no daemons are executing or software installed.
The design goals of Ansible include:
- Minimal in nature. Management systems should not impose additional dependencies on the environment.
- Consistent. With Ansible one should be able to create consistent environments.
- Secure. Ansible does not deploy agents to nodes. Only OpenSSH and Python are required on the managed nodes.
- Highly reliable. When carefully written, an Ansible playbook can be idempotent, to prevent unexpected side-effects on the managed systems. It is entirely possible to have a poorly written playbook that is not idempotent.
- Minimal learning required. Playbooks use an easy and descriptive language based on YAML and Jinja templates.
Idempotence (UK: /ˌɪdɛmˈpoʊtəns/, US: /ˌaɪdəm-/) is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. The concept of idempotence arises in a number of places in abstract algebra (in particular, in the theory of projectors and closure operators) and functional programming (in which it is connected to the property of referential transparency).
The term was introduced by Benjamin Pierce in the context of elements of algebras that remain invariant when raised to a positive integer power, and literally means “(the quality of having) the same power”, from idem + potence (same + power).
Best Ansible Certification Course & Get Noticed By Top Hiring CompaniesWeekday / Weekend BatchesSee Batch Details
Modules are mostly standalone and can be written in a standard scripting language (such as Python, Perl, Ruby, Bash, etc.). One of the guiding properties of modules is idempotency, which means that even if an operation is repeated multiple times (e.g., upon recovery from an outage), it will always place the system into the same state.
The Inventory is a description of the nodes that can be accessed by Ansible. By default, the Inventory is described by a configuration file, in INI or YAML format,whose default location is in /etc/ansible/hosts. The configuration file lists either the IP address or hostname of each node that is accessible by Ansible. In addition, nodes can be assigned to groups.
An example inventory:
- [web servers]
This configuration file specifies three nodes: the first node is specified by an IP address and the latter two nodes are specified by hostnames. Additionally, the latter two nodes are grouped under the web servers group.
Ansible can also use a custom Dynamic Inventory script, which can dynamically pull data from a different system, and supports groups of groups.
Playbooks are YAML files that express configurations, deployment, and orchestration in Ansible, and allow Ansible to perform operations on managed nodes. Each Playbook maps a group of hosts to a set of roles. Each role is represented by calls to Ansible tasks.
Ansible Tower is a REST API, web service, and web-based console designed to make Ansible more usable for IT teams with members of different technical proficiencies and skill sets. It is a hub for automation tasks. Tower is a commercial product supported by Red Hat, Inc. but derived from AWX upstream project, which is open source since September 2017.
There is also another open source alternative to Tower, Semaphore, written in Go.
Control machines have to be a Linux/Unix host (for example SUSE Linux Enterprise, Red Hat Enterprise Linux, Debian, CentOS, macOS, BSD, Ubuntu), and Python 2.7 or 3.5 is required.
Managed nodes, if they are Unix-like, must have Python 2.4 or later. For managed nodes with Python 2.5 or earlier, the python-simplejson package is also required.Since version 1.7, Ansible can also manage Windows nodes.In this case, native PowerShell remoting supported by the WS-Management protocol is used, instead of SSH.
Ansible can deploy to bare metal hosts, virtualized systems and cloud environments, including Amazon Web Services, Atomic, CenturyLink, Cloudscale, CloudStack, DigitalOcean, Dimension Data, Docker, Google Cloud Platform, KVM, Linode, LXC, LXD, Microsoft Azure, OpenStack, Oracle Cloud, OVH, oVirt, Packet, Profitbricks, PubNub, Rackspace, Scaleway, SmartOS, SoftLayer, Univention, VMware, Webfaction, and XenServer.
AnsibleFest is an annual conference of the Ansible community of users, contributors, etc.
|2020||Virtual only due to COVID-19|
Continuous integration and delivery with Ansible :
A major challenge in IT today is centered on enabling continuous integration and continuous deployment (CI/CD) with no downtime. This goal has often required extensive custom code—working with multiple software packages and is a powerful open source automation language. Uniquely, it’s also a deployment and orchestration tool. While Ansible provides more productive drop-in replacements for many core capabilities in other automation solutions, it also seeks to solve other major unsolved IT challenges, such as CI/CD.
Get Ansible Training By Industry Experts to UPGRADE Your Skills
- Instructor-led Sessions
- Real-life Case Studies
Download the whitepaper to learn how to automate your CI/CD pipeline with Ansible.
Ansible Automates 2020
Today, the operational role of IT is obvious. The rapid developments enabled by automation create genuine business value. The results that can be achieved by automation have a direct link to a company’s business goals.
As a CTO or CIO, sometimes you need help articulating this to stakeholders. Translating IT departments’ performance into business prioritized KPIs. Most see efficiency gains, cost and risk reductions, for example. Automation is clearly an executive-level issue.
At first, Ansible was a classical tool that was utilized for specific automation. Ansible helps your team automate routine tasks, so that they can instead focus on what you want to do. The platform enables you to structure work by automating your processes.
Automation is a journey – start yours at Ansible Automates 2020
The global, all-day digital event – Ansible Automates 2020 – takes place on June 10. The event provides inspiration as to how the automation journey can be accelerated and taken to the next level. And no, we’re not going to discuss functionality and technology all day. We want to highlight the cultural and behavioral changes that are linked to the trend towards greater automation. For organizations to achieve the best results, they need to focus on the new tools and tactics at their disposal. At Ansible Automates 2020, we’ll be deep diving at a consultative level. We will discuss both the human and the business aspects of automation.
Ansible Automates 2020 takes place in a more digital, and more unusual, time than ever before With so many unprecedented challenges emerging in the IT sphere, automation can provide increased value and much sought after solutions for teams. The cost efficiencies associated with automation are a top priority right now given the economic challenges that many people are facing.Automation is not a destination; it’s a journey. At Ansible Automates 2020, we’ll be hosting a roundtable with four clients from our broad spectrum of fields. They will discuss and share their respective automation journeys specific to their use cases, key issues and challenges. What would they do differently if they started the same journey again today? What are the challenges they face now? There is enormous value in knowledge sharing, which is a key principle in open source technology.
Automated change is coming:
Those of us who have worked in IT a little longer than we might admit can probably recall some of the old ways we used to get things done. We tested every code ourselves and documented everything we did, from start to finish. But in the early 2000s, creating a more efficient process was increasingly prioritized, adding dedicated teams for testing and documentation to the department. Automation has emerged as a similar watershed moment in time as an integral part of the technological evolution.
Now, striving to automate all manual processes has become second nature, with many organizations accelerating the pace. This has resulted in an increase in the number of change journeys. Almost all of those who see the positive effects of automation undergo a deeper behavioral change.
Advice to those who want to get started with automation:
At Ansible Automates 2020, you will connect with stories on how to get started with automation at more than just a technical level. The event will help you start thinking about important considerations, such as:
- Start by asking yourself the right questions. What do you want to achieve, both from organizational and business perspectives? What are your business goals? Where are you now?
- Actors such as Red Hat will always add new, exciting technology to the mix. As automation becomes increasingly relevant, its related areas of application and creativity grow, which is fantastic. The important thing is to continue to identify the issues mentioned above: what do you need?
- The community exists because they want to help! Set a plan for how to best use the Ansible community, as well as the open source community in general.
Advantages of Ansible
- Free: Ansible is an open-source tool.
- Very simple to set up and use: No special coding skills are necessary to use Ansible’s playbooks (more on playbooks later).
- Powerful: Ansible lets you model even highly complex IT workflows.
Ansible’s Features and Capabilities
Ansible is designed to be very simple, reliable, and consistent for configuration management. If you’re already in IT, you can get up and running with it very quickly. Ansible configurations are simple data descriptions of infrastructure and are both readable by humans and parsable by machines. All you need to start managing systems is a password or an SSH (Secure Socket Shell, a network protocol) key. An example of how easy Ansible makes configuration management: If you want to install an updated version of a specific type of software on all the machines in your enterprise, all you have to do is write out all the IP addresses of the nodes (also called remote hosts) and write an Ansible playbook to install it on all the nodes, then run the playbook from your control machine.
Ansible lets you quickly and easily deploy multi tier apps. You won’t need to write custom code to automate your systems; you list the tasks required to be done by writing a playbook, and Ansible will figure out how to get your systems to the state you want them to be in. In other words, you won’t have to configure the applications on every machine manually. When you run a playbook from your control machine, Ansible uses SSH to communicate with the remote hosts and run all the commands (tasks).
As the name suggests, orchestration involves bringing different elements into a beautifully run whole operation—similar to the way a musical conductor brings the notes produced by all the different instruments into a cohesive artistic work. For example, with application deployment, you need to manage not just the front-end and backend services but the databases, networks, storage, and so on. You also need to make sure that all the tasks are handled in the proper order. Ansible uses automated workflows, provisioning, and more to make orchestrating tasks easy. And once you’ve defined your infrastructure using the Ansible playbooks, you can use that same orchestration wherever you need to, thanks to the portability of Ansible playbooks.
Security and Compliance:
As with application deployment, sitewide security policies (such as firewall rules or locking down users) can be implemented along with other automated processes. If you configure the security details on the control machine and run the associated playbook, all the remote hosts will automatically be updated with those details. That means you won’t need to monitor each machine for security compliance continually manually. And for extra security, an admin’s user ID and password aren’t retrievable in plain text on Ansible.
The first step in automating your applications’ life cycle is automating the provisioning of your infrastructure. With Ansible, you can provision cloud platforms, virtualized hosts, network devices, and bare-metal servers.
Ansible believes you should not need another framework to validate basic things of your infrastructure. This is the case because Ansible is an order-based system that will fail immediately on unhandled errors for a host, and prevent further configuration of that host.Hope you have found all the details that you were looking for, in this article.