Deployment Application on Instances
Ansible provides open-source automation that reduces complexity and runs everywhere. Using Ansible lets you automate virtually any task.
Last updated
Ansible provides open-source automation that reduces complexity and runs everywhere. Using Ansible lets you automate virtually any task.
Last updated
One Ansible Master Node
One or more Ansible Hosts Node
Make sure all the Nodes create the Same SSH_KEY
Check Ansible Master node is the machine we’ll use to connect to and control the Ansible hosts over SSH.
Ubuntu 22.04
Run these commands on all the nodes
Connect all the host nodes with the Master node by using SSH_KEY
Navigate to the .ssh directory to the master node
Create a file like ansible_key
In ansible_key, insert the key you downloaded when creating the server.
Open the downloaded key in Notepad and copy/paste it into the ansible_key file.
Grant access to the key.
Access the host node from the master node.
Ansible as a means of managing your server infrastructure, you need to install the Ansible software on the machine that will serve as the Ansible master node.
To add the official project's PPA (Personal Package Archive) to your system's list of sources in the control node, execute the following command:
Next, refresh your master node
Following the update you can install the Ansible -
To manage your nodes with Ansible, you need to create an inventory file. The inventory file contains information about the hosts you want to manage with Ansible. Here's a quick guide on how to create one.
Choose Your Inventory Format
Ansible supports two formats for inventory files: INI and YAML. The INI format is simpler and more commonly used for small projects or examples. The YAML format provides more flexibility and is preferred for more complex configurations.
INI Format Example:
YAML Format Example:
For INI Format: Simply create a new file with a .ini extension (e.g., inventory.ini) and insert your host information following the INI example format.
For YAML Format: Create a file with a .yml or .yaml extension (e.g., inventory.yml) and structure your host information as shown in the YAML example.
You can choose the format accordingly.
For creating an Inventory file run these commands:-
After creating your inventory file, you can validate it by running the following Ansible command:
Once you have added your servers to the inventory file, verify that Ansible can connect to them and execute commands via SSH.
From your local machine or Ansible master node, run:
When executing any command with Ansible, it's crucial to always specify the path to the host file. You can observe the effect of this practice in the examples below.
Run the following command to check the available spaces and storage.
To check the Uptime of all servers ->
The playbook.yml file is where all your tasks are defined. A task is the smallest unit of action you can automate using an Ansible playbook. But first, create your playbook file using your preferred text editor:
Adding a creating a file task to your playbook.
You’re now ready to run this playbook on one or more servers. Most playbooks are configured to be executed on every server in your inventory by default, but you’ll specify your server this time.
Before running the playbook command, navigate to the playbook directory.
Now we are performing another task to add users to all servers.
Adding creating a user task to your playbook.
Deploying Docker on your worker nodes can be efficiently accomplished using Ansible, a powerful automation tool that simplifies complex configuration tasks and repetitive deployment processes. Below are the steps to achieve a seamless Docker installation across your nodes:
1. Preparation of Inventory File
2. Install Docker Role
3. Create Your Playbook
4. Execute Playbook
Make sure we install the docker by following these steps because docker does not install directly we are adding apt-key-gpg and repository. We are adding apt-key-gpg and a repository inside the playbook.
We have already created the Inventory host file, and now we the creating a playbook for installing docker.
Now check the installed docker and go through individual nodes.
By following these steps, you'll successfully deploy Docker on your worker nodes using Ansible, streamlining your deployment process and ensuring a consistent environment across all nodes.