# Run Ansible Playbook Locally

At times, we require an Ansible Playbook to run locally on the host server. Few examples are given below -

### 1. Using Ansible Commandline

```bash
ansible-playbook --connection=local --inventory 127.0.0.1, playbook_name.yml
```

### 2. Using Ansible Inventory File

We can also, add the host in an inventory file such as -

```ini
127.0.0.1 ansible_connection=local
```

### 3. Using Ansible Configuration File

```code
[defaults]
transport = local
```

### 4. Using Playbook Header

```yaml
- hosts: 127.0.0.1
    connection: local
```

***Source:*** [***GitHub Gist - Ansible playbook Locally***](https://gist.github.com/alces/caa3e7e5f46f9595f715f0f55eef65c1)

***Reference(s):***

* [Configuring Ansible - Ansible Documentation](https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html)
* [Implicit 'localhost' - Ansible Documentation](https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.devjugal.com/ansible/run-ansible-playbook-locally.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
