Manage Linux package in ansible

The yum Ansible module uses the Yum Package Manager on the managed node to handle the package operations. The following example is a playbook that installs the httpd package.

Now we can create a playbook to install apache,

# cat install_it.yaml

---

- hosts: all

become: yes

tasks:

- name: if os is redhat install apache

yum:

name: httpd

state: latest

when: ansible_os_family == "RedHat

Here,

The name keyword gives the name of the package to install.

The state keyword indicates the expected state of the package on the managed host:

*present: Ansible installs the package if it is not already there.

*absent: Ansible removes the package if it is installed.

*latest: Ansible updates the package if it is not already at the most recent available version. If the package is not installed, Ansible installs it.

Let's run the playbook

# ansible-playbook install_it.yaml

PLAY [all] **************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************

ok: [192.168.1.2]

TASK [if os is redhat install apache] ***********************************************************************************************************************

ok: [192.168.1.2]

PLAY RECAP **************************************************************************************************************************************************

192.168.1.2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0



Relevant Blogs:

custom log in ansible 

Ansible Vault  

Introduction to YAML 

AWS CodeBuild: A Fully Managed Build Tool

Recent Comments

No comments

Leave a Comment