How to install 1 package having different names across operating systems !!

While automating the configurations via Ansible, name of packages differs on OS to OS. So, to overcome this problem following is a one-way to solve this issue.

Arpit Bisane
2 min readMar 25, 2021

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.

VARIABLES IN ANSIBLE

You can decide where to set a variable based on the scope you want that value to have. Ansible has three main scopes: Global: this is set by config, environment variables and the command line. Play: each play and contained structures, vars entries (vars; vars_files; vars_prompt), role defaults and vars.

IN THIS DEMOSTRATION

We’ll be taking help from Apache Webserver. And operating systems will be Red Hat Linux and Ubuntu Linux. Package name Httpd is used in Red Hat where as in Ubuntu, Apache2 is the name of the package. Both the operating systems are running on the AWS-Cloud and Ansible will be on our Virtual-Box.

CONFIGURATION FILE OF ANSIBLE

[defaults]
inventory = inventory
command_warnings = false
host_key_checking = false
private_key_file = /root/arpit_aws.pem
ask_pass = false
[privilege_escalation]
become = true
become_user = root
become_method = sudo
become_ask_pass = false

INVENTORY

Make different group of hosts, it will become easier to differentiate them.

[rhel]
65.1.248.133
[ubuntu]
65.2.5.58

VARIABLE FILE

These files are created as such we can call by the OS’s name.

MAIN PLAYBOOK

Run the playbook using below command :

ansible-playbook tasks.yml

Thanks for referring this Blog !

For Complete Demonstration Visit on my LinkedIn handle.

--

--