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