Install Ansible on Arch Linux

28/12/2020
Chưa phân loại

Ansible is a configuration management and provisioning tool. It is very similar to Chef or Puppet.

The good thing about Ansible is that, you don’t have to install anything on the server you want to manage with Ansible. You just install Ansible on the machine from where you want to manage other servers, usually your Laptop or Desktop.

In this article, I will show you how to install and use Ansible on Arch Linux. Let’s get started.

Installing Ansible

Ansible is available in the official package repository of Arch Linux.

To install Ansible, run the following command:

$ sudo pacman -S ansible

Now Press ‘y’ and then press <Enter> to continue.

Ansible should be installed.

Now to check whether Ansible is working correctly or not, run the following command:

$ ansible –version

As you can see from the screenshot below, the version of Ansible installed on my Arch machine is 2.4.3.0. So it is working correctly.

Ansible works using the SSH protocol to connect to different machines for auto management. So you must make sure that SSH is installed on the server or machine that you want to manage or administer with Ansible. I will for the sake of simplicity manage the same Arch Linux machine that has Ansible installed.

If you don’t have SSH installed on your Arch Linux machine, run the following command to install it:

$ sudo pacman -S openssh

Press ‘y’ and then press <Enter> to continue.

SSH should be installed.

Now check whether SSH service is running or not with the following command:

$ sudo systemctl status sshd

As you can see from the screenshot below that it is not running.

You must add SSH to startup. So that it starts automatically on the server you want to manage with Ansible.

Run the following command to add SSH to startup:

$ sudo systemctl enable sshd

SSH should be added to the startup.

Now start SSH with the following command:

$ sudo systemctl start sshd

Now you can check the status of SSH again and it should be running as shown in the screenshot below.

Using Ansible

The configuration file of Ansible is: /etc/ansible/ansible.cfg.

This is how the default configuration file of Ansible on Arch Linux looks like.

Uncomment (by removing the hash symbol) the marked line from the configuration file and save it.

If inventory = /etc/ansible/hosts configuration is enabled, then you can specify what hosts you want to manage in /etc/ansible/hosts file.

Now create a new file /etc/ansible/hosts with the following command:

$ sudo nano /etc/ansible/hosts

Now add the IP address or hostname of the servers that you want to manage with Ansible. In my case, I am adding linuxhint and 127.0.0.1 to the file as shown in the screenshot below.

Now you have to generate a SSH key with the following command:

$ ssh-keygen

Press <Enter> to continue.

Press <Enter> to continue.

Press <Enter> to continue.

A SSH key has been generated.

Now you have to copy the public key to the linuxhint and 127.0.0.1 servers. So that you can login to these servers without any password. If the servers prompt for a password every time, then it will be hard to automate tasks with Ansible.

Run the following command to copy the SSH key to linuxhint server:

$ ssh-copy-id linuxhint

Press ‘yes’ and then press <Enter> to continue.

Enter the password and then press <Enter>.

The SSH key should be added.

Now you can login to linuxhint server without password as you can see in the screenshot below.

I will do the same for 127.0.0.1 server.

$ ssh-copy-id 127.0.0.1

Now you can check whether all the configured servers are up and running with the following command:

$ ansible -m ping all

As you can see from the screenshot below, the pings were successful for both servers.

You can execute a shell command in all of your servers. The format of the command is:

$ ansible -m shell -a ‘YOUR_COMMAND’ all

If you want to execute a shell command in a single server, the format would be:

$ ansible -m shell -a ‘YOUR_COMMAND’ HOSTNAME/IP_ADDR

As you can see from the screenshot below, I execute df -h command in all the configured servers, linuxhint and 127.0.0.1 and the results are displayed.

If you want, you can also execute a shell command in any single configured server as you can see from the screenshot below.

That’s how you install and get started with Ansible on Arch Linux. Thanks for reading this article.

Ansible Tutorial for Beginners

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Add and Remove PPA on Ubuntu

If you’re using Ubuntu, you’re already familiar with the software repository. It’s a HUGE collection of all the necessary...
29/12/2020

How to Parse XML Files Using Python’s BeautifulSoup

Data is literally everywhere, in all kinds of documents. But not all of it is useful, hence the need to parse it to get...
29/12/2020

Cách sử dụng Fail2ban để bảo mật máy chủ CentOS

Mục lục Giới thiệu Cài đặt và cấu hình Giám sát cấu hình firewall và nhật ký Fail2ban Giám...
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024