Ansible is an open-source automation tool used for configuration management, application deployment, and IT coordination. It allows system administrators and DevOps teams to automate repetitive tasks, manage infrastructure as code, and deploy applications seamlessly across multiple servers. Ansible is agentless, meaning it does not require any software installation on target machines.
When paired with Kamatera, Ansible enables seamless cloud management with minimal manual intervention. This guide will walk you through installing Ansible and automating cloud operations on Kamatera.
First, let’s create an account on Kamatera.
Go to console.kamatera.com and sign up for an account by providing the following information:
Enter your username and password and click Login to access Kamatera Management Console.
Navigate to My Cloud on the left pane, select Servers, and click on Create New Server. Alternatively, you can click on Create New Server on the right pane.
Choose the zone from the following options:
Note: For this setup, we used the Asia server domain to set up the Windows Server.
Choose an image
Kamatera offers a variety of app and server images to help users set up preconfigured resources. Users can explore options such as:
In this, select App Images and select Ansible.
Choose the latest version of Ansible.
Note: Always select the latest version.
Once the version is selected you can see message as:
“Ansible CLI latest version installed and ready to use on Ubuntu Server 24.04 LTS”
Toggle the Detailed view button to enable you to view the detailed description, including the price.
For this use case, below Server Specifications are used. Select the server specs that you need.
Choose Server Specs
Field | Description |
Type | Type B-General Purpose: Server CPU are assigned to a dedicated physical CPU thread with reserved resources guaranteed.
Type D–Dedicated: Server CPU are assigned to a dedicated physical CPU Core (2 threads) with reserved resources guaranteed. Type T-Burst: Server CPU are assigned to a dedicated physical CPU thread with reserved resources guaranteed. Exceeding an average usage of 10% will be extra charged for CPUs usage consumption. Type A-Availability: Server CPUs are assigned to a non-dedicated physical CPU thread with no resources guaranteed. Note: More information on CPU types is available on the My Cloud- Pricing page. |
CPU | Choose the number of vCPUs that will be installed on the server. Type B/T can be configured with up to 104 vCPUs per server. Based on Intel’s latest Xeon Processors, 2.7 GHz+. |
RAM | Choose the amount of RAM that will be installed on the server. Type B/T/D can be configured with up to 512GB RAM per server. |
SSD DISK | Choose SSD Storage Size. You can add up to 15 SSD Disk. SSD Storage includes unlimited IOPS and unlimited storage bandwidth, free of charge. |
Daily Backup | Toggle the switch to enable extended daily backups of your server’s storage to external backup storage. |
Management services | Toggle the switch to enable Managed services to the server’s operating system by Kamatera’s Technical Support Team. |
Choose networking
Users can select the network they wish to use, whether it is a public Internet network or a private local network.
Field | Description |
Public Internet Network | Check to connect the server to a network interface connected to Public Internet Network. |
Private Local Network | Check to connect the server to a network interface connected to Private Local Network. |
Field | Description |
NIC #1 | Select WAN from the options available in the drop-down menu.
Select auto from the options available in the drop-down menu.
Select auto from the options available in the drop-down menu.
|
WAN Traffic | Select 5000 GB per month on 10 Gbit per second port. |
Advanced configuration
Field | Description |
Install Script | Enter the script here to execute once the server is created.
Note: For Windows system use Power Shell. |
Keep Server On Failure | Do not terminate server if Start up Script or provisioning sails |
Server Notes | Enter any server notes to be noted. |
Tags | Select the tags from the drop-down menu and click Add Tag. |
Finalize settings
Finalize settings by setting the password, re-validating it, selecting the number of servers, specifying the server’s name, and enabling the Power On Servers option.
Field | Description |
Password | Select password
Password allowed characters: a-z, A-Z,0-9 !@#$^&*()~ and must need the following requirements:
|
Validate | Re-enter the password to validate. |
Servers | Select the number of servers the user wants. |
Name # 1 | Enter the name of the server. |
Power On Servers | Switch on the toggle button to see the details |
Note: Once the user enters the details in Finalize Settings, they can select either the Monthly Billing Cycle or Hourly Billing, depending on their requirements.
Billing Cycle and Pricing
The user can choose between the monthly and hourly billing cycles.
Note: The Server Summary displays the location, operating system (including server specifications), add-on services, servers, and pricing.
Click Create Server.
In Tasks Queue, you can see Ansible is downloading.
Once the installation is successful, you will message as Success beside the server’s name and Ansible is reflected in the Server Management dashboard.
Click Open, beside the Ansible server.
A new screen shows up. The Overview tab in the center is selected by default and it displays information like Power state, Guest OS, Zone, Public Internet (WAN), Server ID of the server and Configuration-Number of CPU. Memory Size, Disk 1. Click on Connect to connect to the server.
Now, click on Open Remote Console.
In the terminal, enter the Username and Password that you mentioned while creating a server (step-8).
You will see
“Default Inventory File: /etc/ansible/hosts”
Ansible uses an inventory file /etc/ansible/hosts by default to define managed nodes.
Run the following command to check the version of Ansible.
Command: ansible –version
Run the command below to know the community version.
Command: ansible-community –version
To edit the the inventory file, run the below command:
Command: sudo nano /etc/ansible/hosts
The /etc/ansible/hosts file is opened, allowing you to add managed nodes. Replace the placeholder IP addresses with your actual server IPs under the [webservers] and [dbservers] groups.
Remove the hash (#) symbols from the commented-out lines and add new IP addresses as shown in the screen below. This ensures that the newly added servers are recognized by Ansible.
Make sure to replace the placeholder IPs with your actual server addresses under the appropriate groups, such as [webservers] and [dbservers].
Once updated, follow these steps:
Ensure the control node can SSH into managed nodes without a password:
Command: ssh-keygen -t rsa -b 4096
This will create an SSH key pair, which you can then copy to managed nodes to enable passwordless SSH authentication for Ansible.
When you run the above command, it prompts
“Enter file in which to save the key (/root/.ssh/id_rsa):” press Enter (Once you press Enter, the key will be saved in the default location).
“Enter passphrase (empty for no passphrase):” press Enter
“Enter same passphrase again:” press Enter.
You will see the message:
This means your private key has been created and stored at /root/.ssh/id_rsa. The private key is confidential and should never be shared. It will be used for authentication when connecting to remote servers.
This means your public key has been saved in /root/.ssh/id_rsa.pub. The public key is safe to share and should be copied to managed nodes. This key allows the managed nodes to recognize and trust your SSH connection.
The fingerprint is a unique identifier for your SSH key.
The below command is used to view the public SSH key that was generated.
Command: sudo nano /root/.ssh/id_rsa.pub
Now you can view the public key in the GNU nano text editor /root/.ssh/id_rsa.pub.
To exit the editor, follow these steps:
Command: ssh-copy-id -i /root/.ssh/id_rsa.pub root@xxx.xxx.xxx.xxx
When prompted:
“Are you sure you want to continue connecting (yes/no/[fingerprint])?” type yes and press Enter.
Then enter the password for the remote user to complete the authentication process.
You will see the message as:
“Now try logging into the machine with “ssh ‘root@xxx.xxx.xxx.xxx’”
This confirms that the SSH key has been successfully copied, and you can now log in without a password.
Now, try logging into machine with “ssh ‘root@xxx.xxx.xxx.xxx’”.
If everything is set up correctly, you should log in without being asked for a password.
Check whether Ansible is installed by running the following command:
Command: ansible –version
If Ansible is not installed, install it by running:
Command: sudo apt install ansible
When prompted “Do you want to continue? [Y/N]”, press ‘Y’.
Once the installation is successful, you can either add the server IP addresses to /etc/ansible/hosts (step 19)
(Or)
create a new file named inventory.ini specifically for storing server and database addresses. To create the inventory.ini file, run the following command to open a file in a Nano editor.
Once the file is opened in nano editor, add Managed Nodes. Edit the inventory file (/etc/ansible/hosts or inventory.ini in your project):
[servers]
xxx.xxx.xxx.xxx
Once updated, follow these steps:
Command: ansible all -m ping -i inventory.ini
If successful, you’ll see:
Now that your Ansible setup is complete, you can start automating tasks on your managed nodes.
To write an Ansible Playbook, first, create a new file by running the following command:
Command: sudo nano sudo nano <playbook-name>.yaml
Replace <playbook-name> with your desired filename (example, install_nginx).
# install_nginx.yaml – name: Install Nginx on managed nodes hosts: [servers] become: yes tasks: – name: Install Nginx apt: name: nginx state: present |
(Or)
If you want to use the default inventory file /etc/ansible/hosts, specify the default group name [webservers] (step 19) in your playbook as follows:
hosts: [webservers]
# install_nginx.yaml – name: Install Nginx on managed nodes hosts: [webservers] become: yes tasks: – name: Install Nginx apt: name: nginx state: present |
Once updated, follow these steps:
To run the playbook using the following command:
Command: ansible-playbook -i inventory.ini install_nginx.yaml
Or,
if you are using the default /etc/ansible/hosts file, run
Command: ansible-playbook -i /etc/ansible/hosts install_nginx.yaml
This will install Nginx on all nodes in the [servers] or [webservers] group.
After running the playbook, you will see output messages indicating the execution status of each task. The output will typically include details such as:
Gathering Facts: Ansible collects system information from the target hosts.
Task Execution Status: Each task in the playbook will display a status message (e.g., ok, changed, failed).
Play Recap: At the end of execution, Ansible provides a summary of the hosts affected, showing the number of tasks that were successful, changed, or failed.
This output confirms that the connection to the server (192.168.1.10) was successful, the Nginx installation task was executed (changed=1 indicates installation), and no errors occurred (failed=0).
Now, run the following command to verify whether Nginx is installed on the node server:
Command: curl http://your-managed-node-ip
This command sends an HTTP request to the specified node server. If Nginx is successfully installed and running, you will receive an HTML response or the default Nginx welcome page. If not, you may encounter a connection error, indicating that Nginx is not installed, or the service is not running.
To exit the node, simply type the following command:
Command: exit
Once you run this command, your SSH session will close, and you will see a message similar to:
logout
Connection to xxx.xxx.xxx.xxx closed.
This indicates that you have successfully logged out from the remote server, and your connection has been terminated.
Congratulations! You have learned how to automate your cloud operations with Ansible on a Kamatera server.
Have additional questions? Search below: