> 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/ansible/tutorials/09__a_quick_introduction_to_dbaas/02a__create_postgres_cluster.yml.md).

# 02a\_\_create\_postgres\_cluster.yml.md

The source files for this tutorial can be downloaded from its [GitHub repository](https://github.com/ionos-cloud/module-ansible/tree/master/docs/), or cloned into your current working directory using the command `git clone https://github.com/ionos-cloud/module-ansible.git` before changing into the `module-ansible/docs/tutorials/09__a_quick_introduction_to_dbaas` sub-directory.

{% code title="01\_\_create\_jumpbox\_and\_nlb.yml" overflow="wrap" lineNumbers="true" %}

```
- name: Set the fact 'internal_lan' based on the above
  ansible.builtin.set_fact:
    internal_lan: "{{ (lan_info_response | json_query(query))[0] }}"
  vars:
    query: "lans[?properties.name=='{{ lan.name }}']"


- name: Get information about our reserved IP Blocks
  ionoscloudsdk.ionoscloud.ipblock_info:
    filters: "{ 'properties.name': 'IP Block for {{ datacenter_name }}' }"
  register: ipblock_info_response
  when: ENABLE_EXPLICITLY_UNSUPPORTED_CONFIGURATIONS


- name: Set 'ip_block' based on the above
  ansible.builtin.set_fact:
    ip_block: "{{ ipblock_info_response.ipblocks[0].properties.ips }}"
  when: ENABLE_EXPLICITLY_UNSUPPORTED_CONFIGURATIONS


- name: Get information about the servers in our data center
  ionoscloudsdk.ionoscloud.server_info:
    datacenter: "{{ datacenter_name }}"
    depth: 5
  register: get_server_response


- name: Retrieve the object describing the jumpbox
  ansible.builtin.set_fact:
    desired_server_info__query: "{{ get_server_response | json_query(query) }}"
  vars:
    query: "servers[?properties.name=='{{ server_config['jumpbox'].name }}']"


- name: Retrieve the jumpbox's public IP
  ansible.builtin.set_fact:
    jumpbox_ip: "{{ (desired_server_info__query[0] | json_query(query))[0] }}"
  vars:
    query: "entities.nics.items[?properties.name!='{{ server_config['jumpbox'].name }}.eth1'].properties.ips[]"




# =======================================================================
# See https://docs.ionos.com/ansible/api/dbaas-postgres/postgres_cluster
- name: Create Postgres Cluster
  ionoscloudsdk.ionoscloud.postgres_cluster:
    postgres_version: 12
    instances: 1
    cores: "{{ dbaas_config.postgres_cluster.cores }}"
    ram: "{{ dbaas_config.postgres_cluster.ram }}"
    storage_size: "{{ dbaas_config.postgres_cluster.volume_size }}"
    storage_type: "{{ dbaas_config.postgres_cluster.storage_type }}"
    location: "{{ location }}"
    connections:
      - cidr: "{{ dbaas_config.postgres_cluster.ip }}/24"
        datacenter: "{{ datacenter_name }}"
        lan: "{{ internal_lan.id }}"
    display_name: "Postgres Cluster for {{ datacenter_name }}"
    synchronization_mode: ASYNCHRONOUS
    db_username: dbadmin
    db_password: "{{ default_password }}"

    wait: true
    wait_timeout: "{{ wait_timeout }}"
  register: postgres_cluster_response    




# =======================================================================
- name: Print usage information
  ansible.builtin.debug:
    msg:
      - "To access your Postgres Cluster via, e.g., psql, use one of the following commands:"
      - "    From the jumpbox:"
      - "        psql -h {{ dbaas_config.postgres_cluster.ip }} -U dbadmin postgres"
      - "    Externally via the jumpbox:"
      - "        In one shell:     ssh -L 5432:{{ postgres_cluster_response.postgres_cluster.properties.dns_name }}:5432 root@{{ jumpbox_ip }}"
      - "        In another shell: psql -h localhost -U dbadmin postgres"
      - "{% if ENABLE_EXPLICITLY_UNSUPPORTED_CONFIGURATIONS %}    Externally via the NLB:{% endif %}"
      - "{% if ENABLE_EXPLICITLY_UNSUPPORTED_CONFIGURATIONS %}        psql -h {{ ip_block[0] }} -U dbadmin postgres{% endif %}"
```

{% endcode %}


---

# 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 dynamically by asking a question.

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

```
GET https://docs.ionos.com/cloud/ansible/tutorials/09__a_quick_introduction_to_dbaas/02a__create_postgres_cluster.yml.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
