Ansible can be used to install application packages like Git, apache, Mysql, etc. These packages can be installed using Ansible Ad-Hoc commands or through ansible Playbooks.
Syntax – To install the git package on the Ubuntu system.
ansible localhost -m apt -a "name=git state=present" -b
- localhost – inventory, the host to be targeted.
- -m module name, here we are using apt for Ubuntu/Debian systems. For the Linux systems using yum.
- -a arguments passed for installation of the package.
- name – package name to be installed.
- state – Ansible provides multiple state options
- present/installed – to install package
- latest – to update the existing package
- absent/removed – to uninstall package
- -b argument to change the owner, like to grant sudo privileges
Output –