> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/tools-ansible/usage/ansibleplaybooks.md).

# Ansible Playbooks

## Ansible Playbooks

Ansible leverages YAML manifest files called Playbooks. The Playbook will describe the infrastructure to build and is processed from top down. Here is a simple Playbook that will provision two identical servers:

`example.yml`:

```yaml
      - hosts: localhost
      connection: local
      gather_facts: false

      tasks:
      - name: Provision a set of instances
          ionoscloudsdk.ionoscloud.server:
              datacenter: Example
              name: server%02d
              auto_increment: true
              count: 2
              cores: 4
              ram: 4096
              image: 25cfc4fd-fe2f-11e6-afc5-525400f64d8d
              image_password: secretpassword
              location: us/las
              assign_public_ip: true
              remove_boot_volume: true
              state: present
          register: ionos
```

> :warning: If you are using names instead of UUIDs to reference objects and they contain field marked with no\_log (such as passwords), they may not work, so please use UUIDs instead in those cases!

**NOT WORKING**:

```yaml
      - hosts: localhost
      connection: local
      gather_facts: false

      tasks:
      - name: Create Cluster
        ionoscloudsdk.ionoscloud.postgres_cluster:
          display_name: test
          db_password: test
        register: cluster_response

      - name: Delete Cluster
      ionoscloudsdk.ionoscloud.postgres_cluster:
          postgres_cluster: "{{ cluster_response.postgres_cluster.properties.display_name }}"
          state: absent
```

In this case you should use the UUID of the cluster as the above example will not work:

**WORKING**:

```yaml
      - hosts: localhost
      connection: local
      gather_facts: false

      tasks:
      - name: Create Cluster
          ionoscloudsdk.ionoscloud.postgres_cluster:
              display_name: test
              db_password: test
          register: cluster_response

      - name: Delete Cluster
          ionoscloudsdk.ionoscloud.postgres_cluster:
              postgres_cluster: "{{ cluster_response.postgres_cluster.id }}"
              state: absent
```

## Execute a Playbook

If your credentials are not already defined:

```bash
export IONOS_USERNAME=username
export IONOS_PASSWORD=password
```

The `ansible-playbook` command will execute the above Playbook.

```bash
ansible-playbook example.yml
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/tools-ansible/usage/ansibleplaybooks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
