Ansible is a popular automation tool used by sysadmins and developers to get computers in a specific state. Ansible modules are, in a way, what commands are to a Linux computer. They provide solutions to specific problems, and one common task when maintaining computers is keeping them updated and consistent. In this article, I show you how to install software packages with Ansible.
Requirements
To run Ansible ad hoc commands and playbooks on managed nodes, a remote user with SSH access is needed on each managed node. For this example, I'll call that user tux. Tux needs permission to run commands with elevated privileges to install packages. Therefore the file /etc/sudoers.d/tux with the following content must exist on all managed nodes:
tux ALL=(ALL) NOPASSWD:ALL
Use visudo to edit the /etc/sudoers file entries.
Package installation
Suppose you've found a cool new package called sysstat that you now want to install on all your hosts at once. That's an easy job for Ansible:
$ ansible all --user tux --become \
--module-name dnf -a’name=sysstat state=latest’
And you're done.
[ You might also like: How to create an Ansible Playbook ]
That one line is called an Ansible ad hoc command. These are usually one-time tasks that you don't expect to repeat. However, in the interest of reusability, it’s better to put such instructions into an Ansible playbook, like this:
---
- hosts: all
tasks:
- name: Make sure the current version of ‘sysstat’ is installed.
dnf:
name: sysstat
state: latest
Save this playbook to a file called install_packages.yml, and then you can run it with the following command:
$ ansible-playbook -u tux -b install_packages.yml
You can put it on a schedule with cron, making sure the desired package gets installed and reinstalled if someone removes it.
Install several packages
What if you want to install a list of packages on all of your hosts? That's easy, too:
---
- hosts: all
tasks:
- name: Package installation
dnf:
name:
- sysstat
- httpd
- mariadb-server
state: latest
Run the playbook:
$ ansible-playbook -u tux -b install_packages.yml
I'm sure you get the idea. Need more packages? Just add them to the list.
Wrap up
Managing software with Ansible is pretty straightforward. You can use the DNF module to manage the actual installation and a YAML-based Ansible playbook to distribute the installation instructions to your managed nodes. This is another excellent example of how Ansible makes life easier for sysadmins who manage many systems.
[ Get this free ebook: Managing your Kubernetes clusters for dummies. ]
저자 소개
Jörg has been a Sysadmin for over ten years now. His fields of operation include Virtualization (VMware), Linux System Administration and Automation (RHEL), Firewalling (Forcepoint), and Loadbalancing (F5). He is a member of the Red Hat Accelerators Community and author of his personal blog at https://www.my-it-brain.de.
유사한 검색 결과
Red Hat Enterprise Linux now available on the AWS European Sovereign Cloud
2025 Red Hat Ansible Automation Platform: A year in review
Technically Speaking | Taming AI agents with observability
A composable industrial edge platform | Technically Speaking
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래