Install a package in Suse-like systems - Ansible module zypper
A real-life example of how to install a package in Suse-like systems: SUSE Linux Enterprise Server and openSUSE


How to Install a package with Ansible in Suse-like systems?
I’m going to show you a live demo with some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible Install a package in Suse-like systems
Today we’re talking about the Ansible module zypper
.
The full name is community.general.zypper
which means is part of the Community General Collection
so maintained by the Ansible Community contributors.
It works on Syse-like operating systems and Manages packages on SUSE and openSUSE via the zypper package manager.
It’s similar to the yum or DNF module for RedHat-like operating systems or the apt module for Debian-like operating systems.
Parameters
- name string - name or package specific
- state string - present / absent / latest
- type string - package / patch / pattern / product / srcpackage / application
- update_cache boolean - no/yes
The parameter list is pretty wide but these four are the most important options.
In the “name” parameter you are going to specify the name of the package or the specific version you would like to install.
The state specifies the action that we would like to perform. In our case for install is “present”.
The type of package to be operated on package / patch / pattern / product / srcpackage / application.
“update_cache” forces to update the repository metadata before the installation. It could be useful to make sure that repositories are up-to-date. The equivalent of console commandzypper refresh
.
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
Let’s jump in a real-life playbook to install a package in Suse-like systems with Ansible.
code
- zypper.yml
---
- name: zypper module demo
hosts: all
become: true
tasks:
- name: install package
community.general.zypper:
name: dos2unix
state: present
execution
output
$ ansible-playbook -i suse/inventory install\ a\ package\ in\ Suse-like\ systems/zypper.yml
PLAY [zypper module demo] *************************************************************************
TASK [Gathering Facts] ****************************************************************************
[WARNING]: Platform linux on host suse.example.com is using the discovered Python interpreter at
/usr/bin/python, but future installation of another Python interpreter could change the meaning of
that path. See https://docs.ansible.com/ansible-
core/2.11/reference_appendices/interpreter_discovery.html for more information.
ok: [suse.example.com]
TASK [install package] ****************************************************************************
changed: [suse.example.com]
PLAY RECAP ****************************************************************************************
suse.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
verification
$ ssh [email protected]
[email protected]:~> sudo su -
suse:~ # zypper se -i dos2unix
Loading repository data...
Warning: Repository 'openSUSE-Leap-42.3-Update' appears to be outdated. Consider using a different mirror or server.
Warning: Repository 'openSUSE-Leap-42.3-Update-Non-Oss' appears to be outdated. Consider using a different mirror or server.
Reading installed packages...
S | Name | Summary | Type
---+----------+---------------------------------------------+--------
i+ | dos2unix | Text converters to and from DOS/MAC to UNIX | package
Recap
Now you know how to install a package of a package in Suse-like systems. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate