Ravindra BagaleCourses & study guides

Chapter 11: Ansible Introduction

11.3 Modules and ad-hoc commands

A module is a unit of work: ping, yum/apt, copy, template, service, user, …

Ad-hoc — one module from the CLI without a full playbook:

ansible -i inventory/hosts.ini badge-api_web -m ping

ansible -i inventory/hosts.ini badge-api_web -m yum -a "name=nginx state=present" --become
# Ubuntu sketch: -m apt -a "name=nginx state=present update_cache=true" --become

ansible -i inventory/hosts.ini badge-api_web -m copy -a "src=files/index.html dest=/usr/share/nginx/html/index.html" --become

ansible -i inventory/hosts.ini badge-api_web -m service -a "name=nginx state=started enabled=true" --become

What you see: ping returns pong. Package module reports changed first run and ok second run if already installed — that is idempotence in action.

Ravindra Bagale's Tip

Inventory madhe wrong user / key path — ping fail. Pehle ssh manual succeed kara, nantar Ansible. Dhyan rakho!