Jump to content

Welcome to CodeNameJessica

โœจ Welcome to CodeNameJessica! โœจ

๐Ÿ’ป Where tech meets community.

Hello, Guest! ๐Ÿ‘‹
You're just a few clicks away from joining an exclusive space for tech enthusiasts, problem-solvers, and lifelong learners like you.

๐Ÿ” Why Join?
By becoming a member of CodeNameJessica, youโ€™ll get access to:
โœ… In-depth discussions on Linux, Security, Server Administration, Programming, and more
โœ… Exclusive resources, tools, and scripts for IT professionals
โœ… A supportive community of like-minded individuals to share ideas, solve problems, and learn together
โœ… Project showcases, guides, and tutorials from our members
โœ… Personalized profiles and direct messaging to collaborate with other techies

๐ŸŒ Sign Up Now and Unlock Full Access!
As a guest, you're seeing just a glimpse of what we offer. Don't miss out on the complete experience! Create a free account today and start exploring everything CodeNameJessica has to offer.

by: Adnan Shabbir
Mon, 23 Jun 2025 12:34:03 +0000


Basic Workflow of Ansible | What components are necessary

sudo apt update

sudo apt install ansible

ansible --version

Ansible Control Node IP: 192.168.140.139 (Where Ansible is configured)

Ansible Host IPs: {

Server 1 [172.17.33.7]

Server2 [192.168.18.140]

}

Inventory File:

Default inventory file location: /etc/ansible/hosts. Usually, it is not available when we install Ansible from the default repositories of the distro, so we need to create it anywhere in the filesystem. If we create it in the default location, then no need to direct Ansible to the location of the file.

However, when we create the inventory file other than the default, we need to tell Ansible about the location of the inventory file.

Inventory listing (Verifying the Inventory Listing):

ansible-inventory --list -y

SSH (as it is the primary connection medium of Ansible with its hosts):

sudo apt install ssh

Allow port 22 through the firewall on the client side:

sudo ufw allow 22

Letโ€™s check the status of the firewall:

sudo ufw status

Step 2: Establish a No-Password Login on a Specific Username | At the Host End

Create a new dedicated user for the Ansible operations:

sudo adduser username

Adding the Ansible user to the sudo group:

sudo usermod -aG sudo ansible_root

Add the user to the sudo group (open the sudoers file):

sudo nano /etc/sudoers

SSH Connection (From Ansible Control Node to one Ansible Host):

ssh username@host-ip-address

ansible all -m ping -u ansible_root

SSH key generation and copying the public key to the remote host:

ssh-keygen

Note: Copy the public key to the user that you will be using to control the hosts on various machines.

ssh-copy-id username@host-ip-address

Test All the Servers Listed in the Inventory File:

Testing the Ansible Connection to the Ansible host (remember to use the username who is trusted at the host or has a passwordless login). I have the user โ€œadnanโ€ as the trusted user in the Ansible user list.

ansible all -m ping -u username

Same with the different username configured on the host side:

We can ping a specific group, i.e., in our case, we have a group named [servers] in the inventory.

 

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.