This lab demonstrates how to use an Ansible playbook to install required packages (curl and git) on a remote server. It ensures idempotent execution and highlights package management automation.
.
├── hosts.ini
└── install_packages.ymlvi hosts.ini[webservers]
server1 ansible_user=server1_admin ansible_ssh_pass='server1_admin@123!' ansible_become=true ansible_become_pass='server1_admin@123!'vi install_packages.yml---
- name: Install curl and git on server1
hosts: server1
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
- name: Install curl and git
apt:
name:
- curl
- git
state: presentansible-playbook -i hosts.ini install_packages.ymlExecutes the playbook and installs required packages on server1.
- Playbook-based package management
- Installing multiple packages using
apt - Idempotent execution (
state: present) - Privilege escalation using
become
This lab demonstrates how Ansible can automate package installation across servers, ensuring required tools are installed only when needed.