KodeKloud Engineer Day 87: Ansible Install Package.
Hey Everyone! I have taken up the kodekloud engineer daily challenge [100 days of Devops] and through this series, we shall slowly but…
KodeKloud Engineer Day 87: Ansible Install Package.
Hey Everyone! I have taken up the kodekloud engineer daily challenge [100 days of Devops] and through this series, we shall slowly but steadily start solving the daily challenges.
Here’s the link to get started with the challenge: https://engineer.kodekloud.com/practice
Day #87 Task: Ansible Install Package.
The Nautilus Application development team wanted to test some applications on app servers in
Stratos Datacenter. They shared some pre-requisites with the DevOps team, and packages need to be installed on app servers. Since we are already using Ansible for automating such tasks, please perform this task using Ansible as per details mentioned below:
- Create an inventory file
/home/thor/playbook/inventoryonjump hostand add all app servers in it.
- Create an Ansible playbook
/home/thor/playbook/playbook.ymlto installlogrotatepackage onall app serversusing Ansibleyummodule.
- Make sure user
thorshould be able to run the playbook onjump host.
Note:Validation will try to run playbook using commandansible-playbook -i inventory playbook.ymlso please make sure playbook works this way, without passing any extra arguments.

Day #87 Task: Ansible Install Package.
Step-1: Setup SSH Key-Based Authentication between the jumphost and all the app-servers.
# Setup SSH Key-Based Authentication between the jumphost and all the app-servers.
thor@jump-host ~$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/thor/.ssh/id_ed25519):
Created directory '/home/thor/.ssh'.
Enter passphrase for "/home/thor/.ssh/id_ed25519" (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/thor/.ssh/id_ed25519
Your public key has been saved in /home/thor/.ssh/id_ed25519.pub
The key fingerprint is:
The key's randomart image is:
<randomart-image>
thor@jump-host ~$ ls -la .ssh/
total 24
drwx------ 2 thor thor 4096 May 23 11:01 .
drwx------ 1 thor thor 4096 May 23 11:00 ..
-rw------- 1 thor thor 411 May 23 11:01 id_ed25519
-rw-r--r-- 1 thor thor 96 May 23 11:01 id_ed25519.pub
-rw-r--r-- 1 thor thor 3429 May 23 10:41 known_hosts
# Copy the public key to App Server 01. Repeat the same step for the other two app servers.
thor@jump-host ~$ ssh-copy-id tony@stapp01
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/thor/.ssh/id_ed25519.pub"
The authenticity of host 'stapp01 (10.244.195.218)' can't be established.
ED25519 key fingerprint is SHA256:ePpj2V33VpaJNIZvEhgY9ja1lW4qFRaRzBgHvvfWQiQ.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
tony@stapp01's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'tony@stapp01'"
and check to make sure that only the key(s) you wanted were added.
thor@jump-host ~$ ssh tony@stapp01
[tony@stapp01 ~]$ exit
logout
Connection to stapp01 closed.
Now, that it’s setup, let’s create the inventory file and see, if it runs successfully.
Step-2: Create the inventory file.
As given in the question, we need to create the inventory file in the path */home/thor/playbook/inventory*on the jumphost. Let’s create it to use the SSH Key-Based Authentication approach.
# Create the inventory file.
thor@jump-host ~$ vi /home/thor/playbook/inventory
# Content of the inventory file.
[app_servers]
stapp01 ansible_host=stapp01 ansible_user=tony
stapp02 ansible_host=stapp02 ansible_user=steve
stapp03 ansible_host=stapp03 ansible_user=banner
Step-3: Create the playbook file.
We must create the playbook in this path: */home/thor/ansible/playbook.yml*.
And on executing this playbook, it must successfully install the *logrotatepackage using the `yum`*module.
thor@jump-host ~/playbook$ cat playbook.yml
---
- hosts: app_servers
become: yes
tasks:
- name: Install logrotate package.
yum:
name: logrotate
state: present
Step-4: Validate the execution of the playbook against the inventory file.
Check in all the app servers, before executing the playbook file, if any such package exists.
# Check in the app-server 01 if the logrotate package is already installed. Repeat the same for the other app servers.
thor@jump-host ~$ ssh tony@stapp01
[tony@stapp01 ~]$ sudo systemctl status logrotate
Unit logrotate.service could not be found.
# Execute the playbook against the inventory and check if the logrotate package is installed in all the app servers.
thor@jump-host ~$ cd playbook/
thor@jump-host ~/playbook$ ansible-playbook -i inventory playbook.yml
PLAY [app_servers] **********************************************************************
TASK [Gathering Facts] ******************************************************************
ok: [stapp03]
ok: [stapp01]
ok: [stapp02]
TASK [Install logrotate package.] *******************************************************
changed: [stapp02]
changed: [stapp03]
changed: [stapp01]
PLAY RECAP ******************************************************************************
stapp01 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
stapp02 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
stapp03 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
# Check in the app-server 01 if the logrotate package is installed successfully. Repeat the same for the other app servers.
[tony@stapp01 ~]$ sudo systemctl status logrotate
○ logrotate.service - Rotate log files
Loaded: loaded (/usr/lib/systemd/system/logrotate.service; static)
Active: inactive (dead)
TriggeredBy: ○ logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
That’s it for Day #87. Let’s hop on to the next challenge! See you there! Toodaloo!
메타데이터
- post_id
- 6b552e66bcbd
- slug
- kodekloud-engineer-day-87-ansible-install-package-6b552e66bcbd
- url
- https://medium.com/@janemils/kodekloud-engineer-day-87-ansible-install-package-6b552e66bcbd
- canonical_url
- https://medium.com/@janemils/kodekloud-engineer-day-87-ansible-install-package-6b552e66bcbd
- author_url
- https://medium.com/@janemils
- status
- ok
- fetched_at
- 2026-06-09 15:37:30