# Installing and Your First Command — Ansible: Automate Servers with Playbooks

Source: https://www.geekswithgeeks.com/en/ansible/ans-install-adhoc

> Install Ansible, check the version and run an ad-hoc command against hosts.

## Install on the control node only

Install Ansible on **one** machine (your laptop or a build server): on Debian/Ubuntu with `sudo apt install ansible`, or with `pipx install ansible` / `pip install ansible`. Managed hosts need only SSH and Python. An **ad-hoc command** runs one module once, without a playbook, for quick checks: `ansible <hosts> -m <module> -a "<args>"`. The `ping` module checks that Ansible can connect and run Python; it is not an ICMP ping.

## Ping the web group

I ran this on this machine with `ansible_connection=local` hosts (so no SSH is needed for the demo). `pong` means the module ran successfully.

```bash
ansible --version | head -1
ansible -i inventory.ini web -m ping
```

Output:

```
ansible [core 2.16.3]
web1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}
web2 | SUCCESS => { ... same ... }
```

## Ad-hoc for quick facts, playbooks for repeatable work

Use ad-hoc commands to check uptime or disk space across servers. Anything you will run twice belongs in a playbook under version control.

**Quiz:** Where must Ansible be installed?

- [x] Only on the control node
- [ ] On every managed host
- [ ] Inside every container image
- [ ] Nowhere, it is a website

*Answer:* Only on the control node. Managed hosts need only SSH and Python, not Ansible itself.
