ad-hoc commands
1. Apt update
Chạy như này sẽ lỗi vì cần sudo để update change trong server
ansible all -m apt -a update_cache=true
Chạy bằng sudo
ansible all -m apt -a update_cache=true --become --ask-become-pass
2. Cài package
Ví dụ: Cài vim-nox
ansible all -m apt -a name=vim-nox --become --ask-become-pass
SSH vào server, check xem cài chưa
apt search vim-nox
Server sẽ show [installed] như dưới => Đã cài được
nghiant@bookstack:~$ apt search vim-nox
Sorting... Done
Full Text Search... Done
vim-nox/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.8 amd64 [installed]
Vi IMproved - enhanced vi editor - with scripting languages support
vim-tiny/noble-updates,noble-security,now 2:9.1.0016-1ubuntu7.8 amd64 [installed,automatic]
Vi IMproved - enhanced vi editor - compact version
3. Cập nhật package lên version mới
Check bằng lệnh này xem package nào có thể upgrade. Giả sử là snapd
sudo apt dist-upgrade
Chạy lệnh dưới để update
ansible all -m apt -a "name=snapd state=latest" --become --ask-become-pass
Sau đó check lại bằng apt dist-upgrade sẽ thấy không còn snapd trong list nữa => Đã up lên version mới