# Dynamic inventory

Download ec2.py from [here](https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.py). Save it in your Ansible root folder.

Edit `ansible.cfg` as follows:

```bash
...
inventory = ./ec2.py
...
```

Your playbook host must be as follows:

```bash
...
hosts: "{{ variable_host | default('tag_tfplayer_vpninstance') }}"
...
```

Run the playbook:

```
ansible-playbook playbooks/vpn.yml \
  --extra-vars "variable_host=tag_tfplayer_vpninstance"
```

{% hint style="info" %}
`variable_host` is the EC2 instance tag. In this example the tag name is `tfplayer` and the tag content is `vpninstance`.
{% endhint %}


---

# 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://www.devops.buzz/public/ansible/dynamic-inventory.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.
