What if Things Turn Out Great?

As a Certified Life & Relationship Coach, I’m in the Positive Psychology business. However, that doesn’t mean I’m always positive. To the contrary, I’m wired for anxiety, hypervigilance, and negative…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




All You Need To Know About Ansible ft. Ansible Playbook to Deploy Apache2

Ansible is a software tool that provides simple but powerful automation for cross-platform server support. It is primarily intended for IT professionals, who use it for application deployment, run updates on server nodes, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis.

Ansible works on master-slave architecture. A control node is a computer machine that has Ansible deployed and runs playbooks whereas the managed node executes the tasks defined in the Ansible playbook.

Ansible works by connecting to nodes (clients, servers etc.) through SSH protocol connection, and then sending a small program to that node. A playbook is a configuration file written in YAML that provides instructions for what needs to be done in order to bring a managed node into the desired state. Playbooks are meant to be simple, human-readable, and self-documenting. Playbooks consist of multiple plays that are discrete units of code to carry out the actual task.

Ansible automates and simplifies repetitive, complex, and tedious operations. Though there are many other configuration management tools available in the market like Puppet, Saltstack and Chef popularly, but Ansible remains the preferred choice. This is in light of the following reasons:

Ansible Galaxy is simply a hub for sharing Ansible playbooks and roles. A Galaxy is a repo that can be initialized like git and contains independent roles.

The control plane for Ansible Automation Platform is the automation controller (replacing Ansible Tower). It is a web-based proprietary alternative to traditional open-source CLI. It includes a user interface (UI), role-based access control (RBAC), workflows, 24x7 support from RedHat Enterprise, and other functionalities. However, it comes at a cost.

In this article, we’ll go through steps to install Ansible and write a simple playbook to ping-pong and deploy apache2 on a remote node.

Ansible can be installed simply by executing this command:

or

The next step is to add the credentials of the remote node in the Ansible hosts file. The hosts file is located in the /etc/ansible directory. Type in this command to edit the hosts file:

hosts file in /etc/ansible directory

The credentials include the remote node’s IP address and the username. These values must be specified inside of a hosts block (servers, in my case), which acts as a pointer to the remote node. Any entry specified inside this block will belong to a group on which the Ansible task will take effect.

note: I have also specified the port number i.e. 3022 in the IP address because I have a virtual machine as my target node with port forwarding enabled.

Ping the remote node by running this command to verify the connection between ansible and the node:

Output of successful connection verification

Ansible playbook acts a blueprint of the tasks. A typical playbook consists of instructions in a YAML format. Here is a simple playbook that installs apache2 on a node.

Ansible playbook to install apache2

This playbook has following instructions:

To run the playbook execute this command:

Output for successful playbook execution

The changed flag indicates that the playbook has been executed successfully by changing the target node’s state.

Head to the target node and type in localhost in the browser. Apache2 has been successfully deployed in the target node.

Apache2 is deployed successfully

Add a comment

Related posts:

ica10 companies revolutionising blockchain technology in Africa

Accenture estimates that the banking sector could make an estimated USD 12 BILLION yearly by utilising blockchain technology. As keen interest emerges in the potential for blockchain, major vendors…

Deploying Angular with Java Backend on GCP GKE using HELM

Kubernetes is one of the rapidly growing technology and all the companies are adopting it nowadays. When you run any application on Kubernetes you need to deploy so many objects such as deployment…

insomniac

it permeates my skin as i’m brushing it off. you protect, you, my armor of a man. i think of years from now — is it what i see now or where will i be? there there there or in a field, galloping. i…