postgresql_cluster icon indicating copy to clipboard operation
postgresql_cluster copied to clipboard

allow option to enable or disable public ip for instance

Open pen-pal opened this issue 6 months ago • 8 comments

currently if we try to create ec2 instance in aws in private subnet due to assign_public_ip set to true, even in private subnet the instance tries to assign public ip to the instance which does not work. this allows us to disable public ip to the instance

pen-pal avatar May 26 '25 13:05 pen-pal

There are several places in the code where a public address is expected (instances[0].public_ip_address), so for this to work, it's not enough to add just one variable, you also need to take into account the case of access only to a private address.

vitabaks avatar May 26 '25 15:05 vitabaks

There are several places in the code where a public address is expected (instances[0].public_ip_address), so for this to work, it's not enough to add just one variable, you also need to take into account the case of access only to a private address.

update the public ip usage accordingly on the related section.

pen-pal avatar May 27 '25 03:05 pen-pal

This code still needs to be finalized. In its current form, it will fail when deploying over a public network, since private_ip_address is now explicitly specified in the wait_for module.

I’ll try to make time to finalize this PR. Also, I believe it would make sense to implement similar logic for other cloud providers, not just AWS.

vitabaks avatar May 27 '25 07:05 vitabaks

i can work on the changes if you can direct me

pen-pal avatar May 27 '25 15:05 pen-pal

@pen-pal I've made a few changes, please take a look and test it.

vitabaks avatar May 28 '25 07:05 vitabaks

@vitabaks the above changes look good

pen-pal avatar May 29 '25 05:05 pen-pal

@pen-pal Do you have time to add an option for other cloud providers or should I do it?

vitabaks avatar May 29 '25 08:05 vitabaks

@pen-pal Do you have time to add an option for other cloud providers or should I do it?

might take me time for other cloud resources

pen-pal avatar May 29 '25 10:05 pen-pal

I can continue and complete this PR for other cloud providers.

vitabaks avatar Jun 29 '25 15:06 vitabaks

Test: AWS

Spot instance

docker run --rm -it \
  --env AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
  --env AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
  automation:local \
    ansible-playbook deploy_pgcluster.yml --extra-vars \
      "ansible_user=ubuntu \
       cloud_provider='aws' \
       cloud_load_balancer=false \
       server_public_ip=false \
       server_spot=true \
       server_count=3 \
       server_type='t3.medium' \
       server_image='ami-063fb82b183efe67d' \
       server_location='us-east-1' \
       system_volume_size=20 \
       volume_size=10 \
       aws_s3_bucket_create=false \
       pgbackrest_auto_conf=false \
       postgresql_version=17 \
       patroni_cluster_name=vitabaks-pgcluster \
       ssh_public_keys='ssh-rsa AAAAB3NzaC1yc2EAAAABJQA*******xGqHVdlBFMsucuIRnTBcgGYlKHAzKCMEQMgXDn4jeLUzA+2mhhxIaTufcvgX9kfcyLni4ceO6/w+YyNozpEzbGg63wX2uPq35NlVL6Bn/whzcMINzKKCc7AVGbk='"

Result: OK

PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] *******************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set variable: 'pgbackrest_install' to configure Postgres backups] *****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] *****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] *************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] ***********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on controlling host] *****************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'boto3' dependency is present on controlling host] ********************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : AWS: Remove temporary SSH key 'ssh_key_tmp_mogonuo' from cloud (if any)] **********************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Add SSH key 'ssh_key_tmp_mogonuo' to cloud] **********************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Gather information about default VPC] ****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Gather information about VPC subnet for default VPC] *************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: vpc_id] *************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: server_network] *****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Create or modify Security Group] *********************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ip_address_type] ****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Gather information about EC2 Spot instances] *********************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01)
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02)
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : AWS: Create a request for EC2 Spot instance] **************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : AWS: Rename the EC2 Spot instance] ************************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Set variable: server_result] ******************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Server info] **********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "i-05a5173b61d6edcac",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "172.31.43.145",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "i-031d0ccb6f971c9ec",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "172.31.35.144",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "i-0e9fe6d1e981e43dd",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "172.31.40.59",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
  • no pubic ip

image

Non-spot

server_spot=false

Result:

TASK [vitabaks.autobase.cloud_resources : AWS: Create or modify EC2 instance] ***********************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Server info] **********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "i-0ae049eaa73aceb6e",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "172.31.41.162",
        "public_ip": "3.91.24.140",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "i-00d6a2f1175a68b85",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "172.31.36.176",
        "public_ip": "34.201.122.19",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "i-09e2ea4988a33c0f1",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "172.31.37.120",
        "public_ip": "34.230.60.20",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}

The public IP was created anyway.

image

cc @pen-pal

vitabaks avatar Jul 06 '25 15:07 vitabaks

@vitabaks i ran the script previoulsy but none of them got public ips on my end setting server_public_ip to false

pen-pal avatar Jul 07 '25 05:07 pen-pal

we should merge this @vitabaks if all is working as expected?

pen-pal avatar Jul 10 '25 15:07 pen-pal

i ran the script previoulsy but none of them got public ips on my end setting server_public_ip to false

In my case, it worked after disabling the "Auto-assign public IPv4 address" option for the subnet.

image
PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] ******************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Set variable: 'pgbackrest_install' to configure Postgres backups] ****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] ****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] ************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] **********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on controlling host] ****************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'boto3' dependency is present on controlling host] *******************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : AWS: Remove temporary SSH key 'ssh_key_tmp_dpwzdmn' from cloud (if any)] *********************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Add SSH key 'ssh_key_tmp_dpwzdmn' to cloud] *********************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Gather information about default VPC] ***************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Gather information about VPC subnet for default VPC] ************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: vpc_id] ************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: server_network] ****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Create or modify Security Group] ********************************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ip_address_type] ***************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : AWS: Create or modify EC2 instance] **********************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Server info] *********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "i-0b586e7ffe6c47ee4",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "172.31.34.30",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "i-0aaf4db9d841180d2",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "172.31.45.27",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "i-013f5f564a65fc334",
        "image": "ami-063fb82b183efe67d",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "172.31.39.241",
        "public_ip": "N/A",
        "type": "t3.medium",
        "volume_size": "10 GB"
    }
}

vitabaks avatar Jul 10 '25 16:07 vitabaks

Test: GCP

docker run --rm -it \
  --env GCP_SERVICE_ACCOUNT_CONTENTS=${GCP_SERVICE_ACCOUNT_CONTENTS} \
  automation:local \
    ansible-playbook deploy_pgcluster.yml --extra-vars \
      "ansible_user=root \
       cloud_provider='gcp' \
       cloud_load_balancer=false \
       server_public_ip=false \
       server_spot=false \
       server_count=3 \
       server_type='e2-medium' \
       server_image='projects/ubuntu-os-cloud/global/images/family/ubuntu-2404-lts-amd64' \
       server_location='us-east1' \
       system_volume_size=20 \
       volume_size=10 \
       gcp_bucket_create=false \
       pgbackrest_auto_conf=false \
       postgresql_version=17 \
       patroni_cluster_name=vitabaks-pgcluster \
       ssh_public_keys='ssh-rsa AAAAB3NzaC1yc2EAAAABJQAA********bGg63wX2uPq35NlVL6Bn/whzcMINzKKCc7AVGbk='"

Result: OK

PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] *****************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] ***************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] ***********************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] *********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on controlling host] ***************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'google-auth' dependency is present on controlling host] ************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Lookup the GCP_SERVICE_ACCOUNT_CONTENTS environmental variable] *****************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: gcp_service_account_contents] *************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Gather information about project] ******************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: gcp_network_name] *************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Gather information about network] ******************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Extract ip_range for network 'default'] ************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Create or modify Netdata public firewall rule] *****************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Create or modify Postgres cluster firewall rule] ***************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : GCP: Create or modify VM instance] **********************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Server info] ********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "1328542681751766195",
        "image": "ubuntu-2404-lts",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "10.142.0.28",
        "public_ip": "N/A",
        "type": "e2-medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "6448872820821869727",
        "image": "ubuntu-2404-lts",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "10.142.0.29",
        "public_ip": "N/A",
        "type": "e2-medium",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "2590454152635237480",
        "image": "ubuntu-2404-lts",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "10.142.0.30",
        "public_ip": "N/A",
        "type": "e2-medium",
        "volume_size": "10 GB"
    }
}
  • no public ip
image

passed

vitabaks avatar Jul 10 '25 16:07 vitabaks

Test: Azure

docker run --rm -it \
  --env AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} \
  --env AZURE_CLIENT_ID=${AZURE_CLIENT_ID} \
  --env AZURE_SECRET=${AZURE_SECRET} \
  --env AZURE_TENANT=${AZURE_TENANT} \
  automation:local \
    ansible-playbook deploy_pgcluster.yml --extra-vars \
      "ansible_user=azureadmin \
       cloud_provider='azure' \
       cloud_load_balancer=false \
       server_public_ip=false \
       server_spot=false \
       server_count=3 \
       server_type='Standard_B2s' \
       server_location='eastus' \
       system_volume_size=30 \
       volume_size=10 \
       azure_blob_storage_create=false \
       pgbackrest_auto_conf=false \
       postgresql_version=17 \
       patroni_cluster_name=vitabaks-pgcluster \
       ssh_public_keys='ssh-rsa AAAAB3NzaC1yc2EAA*******63wX2uPq35NlVL6Bn/whzcMINzKKCc7AVGbk='"

Result: OK

PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] ******************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] ****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] ************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] **********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on controlling host] ****************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that Azure collection is installed on controlling host] *******************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Get ansible_collections path] ****************************************************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that Azure collection requirements is present on controlling host] ********************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Azure: Create resource group] ****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Azure: Create virtual network] ***************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Azure: Create subnet] ************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Azure: Gather information about network] *****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Azure: Create or modify Security Group] ******************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Azure: Create network interface] *************************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01-network-interface)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02-network-interface)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03-network-interface)

TASK [vitabaks.autobase.cloud_resources : Azure: Create virtual machine] ***************************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Extract virtual machine private IPs] *********************************************************************************************************************************
ok: [localhost] => (item=10.0.1.4)
ok: [localhost] => (item=10.0.1.5)
ok: [localhost] => (item=10.0.1.6)

TASK [vitabaks.autobase.cloud_resources : Server info] *********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "/subscriptions/2473ddde-6323-4e2d-9a43-3865da76e6e9/resourceGroups/postgres-cluster-resource-group-eastus/providers/Microsoft.Compute/virtualMachines/vitabaks-pgcluster-pgnode01",
        "image": {
            "exact_version": "22.04.202506200",
            "offer": "0001-com-ubuntu-server-jammy",
            "publisher": "Canonical",
            "sku": "22_04-lts-gen2",
            "version": "22.04.202506200"
        },
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "10.0.1.4",
        "public_ip": "N/A",
        "type": "Standard_B2s",
        "volume_size": "10 GB",
        "volume_type": "StandardSSD_LRS"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "/subscriptions/2473ddde-6323-4e2d-9a43-3865da76e6e9/resourceGroups/postgres-cluster-resource-group-eastus/providers/Microsoft.Compute/virtualMachines/vitabaks-pgcluster-pgnode02",
        "image": {
            "exact_version": "22.04.202506200",
            "offer": "0001-com-ubuntu-server-jammy",
            "publisher": "Canonical",
            "sku": "22_04-lts-gen2",
            "version": "22.04.202506200"
        },
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "10.0.1.5",
        "public_ip": "N/A",
        "type": "Standard_B2s",
        "volume_size": "10 GB",
        "volume_type": "StandardSSD_LRS"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "/subscriptions/2473ddde-6323-4e2d-9a43-3865da76e6e9/resourceGroups/postgres-cluster-resource-group-eastus/providers/Microsoft.Compute/virtualMachines/vitabaks-pgcluster-pgnode03",
        "image": {
            "exact_version": "22.04.202506200",
            "offer": "0001-com-ubuntu-server-jammy",
            "publisher": "Canonical",
            "sku": "22_04-lts-gen2",
            "version": "22.04.202506200"
        },
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "10.0.1.6",
        "public_ip": "N/A",
        "type": "Standard_B2s",
        "volume_size": "10 GB",
        "volume_type": "StandardSSD_LRS"
    }
}
  • no public ip
image

passed

vitabaks avatar Jul 10 '25 17:07 vitabaks

we should merge this if all is working as expected?

Very soon. We should not rush, it is important to do it reliably and test it well.

vitabaks avatar Jul 10 '25 17:07 vitabaks

Test: DigitalOcean

Note: The digital_ocean_droplet module doesn't support disabling public IP, but we do not open public SSH access in Firewall and use private IP if server_public_ip: false

docker run --rm -it \
  --env DO_API_TOKEN=${DO_API_TOKEN} \
  automation:local \
    ansible-playbook deploy_pgcluster.yml --extra-vars \
      "ansible_user=root \
       cloud_provider='digitalocean' \
       cloud_load_balancer=false \
       server_public_ip=false \
       server_count=3 \
       server_type='s-2vcpu-4gb' \
       server_image='ubuntu-24-04-x64' \
       server_location='nyc1' \
       system_volume_size=20 \
       volume_size=10 \
       digital_ocean_spaces_create=false \
       pgbackrest_auto_conf=false \
       postgresql_version=17 \
       patroni_cluster_name=vitabaks-pgcluster \
       ssh_public_keys='ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEA*******ozpEzbGg63wX2uPq35NlVL6Bn/whzcMINzKKCc7AVGbk='"

Result:

PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] *******************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] *****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] *************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] ***********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on control host] *********************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'dopy' dependency is present on control host] *************************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Remove temporary SSH key 'ssh_key_tmp_fyorkob' from cloud (if any)] *************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Add SSH key 'ssh_key_tmp_fyorkob' to cloud] *************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Gather information about SSH keys] **********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Get fingerprint for SSH key 'ssh_key_tmp_fyorkob'] ******************************************************************************************************
ok: [localhost] => (item=ssh_key_tmp_fyorkob)

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Gather information about VPC] ***************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Extract ip_range from default VPC] ************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Create a tag 'vitabaks-pgcluster'] **********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Create or modify public firewall] ***********************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Create or modify Postgres cluster firewall] *************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Create or modify Droplet] *******************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Create or modify Block Storage] *************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03-storage)

TASK [vitabaks.autobase.cloud_resources : DigitalOcean: Attach Block Storage to Droplet] ************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03-storage)

TASK [vitabaks.autobase.cloud_resources : Server info] **********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "507908964",
        "image": "Ubuntu 24.04 (LTS) x64",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "10.116.0.18",
        "public_ip": "137.184.55.227",
        "type": "s-2vcpu-4gb",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "507909076",
        "image": "Ubuntu 24.04 (LTS) x64",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "10.116.0.17",
        "public_ip": "157.245.246.241",
        "type": "s-2vcpu-4gb",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "507909165",
        "image": "Ubuntu 24.04 (LTS) x64",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "10.116.0.16",
        "public_ip": "165.227.80.203",
        "type": "s-2vcpu-4gb",
        "volume_size": "10 GB"
    }
}

check:

vitabaks@MacBook-Pro-Vitaliy ~ % ssh [email protected]
ssh: connect to host 137.184.55.227 port 22: Operation timed out
  • no access via public IP
image
  • no rule for ssh

passed

vitabaks avatar Jul 14 '25 09:07 vitabaks

Test: Hetzner Cloud

docker run --rm -it \
  --env HCLOUD_API_TOKEN=${HCLOUD_API_TOKEN} \
  automation:local \
    ansible-playbook deploy_pgcluster.yml --extra-vars \
      "ansible_user=root \
       cloud_provider='hetzner' \
       cloud_load_balancer=false \
       server_public_ip=false \
       server_count=3 \
       server_type='CX22' \
       server_image='ubuntu-24.04' \
       server_location='fsn1' \
       system_volume_size=20 \
       volume_size=10 \
       hetzner_object_storage_create=false \
       pgbackrest_auto_conf=false \
       postgresql_version=17 \
       patroni_cluster_name=vitabaks-pgcluster \
       ssh_public_keys='ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAgEA0TU9Yo******ozpEzbGg63wX2uPq35NlVL6Bn/whzcMINzKKCc7AVGbk='"

Result:

PLAY [vitabaks.autobase.deploy_pgcluster | Deploy PostgreSQL HA Cluster (based on "Patroni")] ******************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a unique temporary SSH key name] ****************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Generate a new temporary SSH key to access the server for deployment] ************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_name and ssh_key_content] **********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'python3-pip' package is present on control host] ********************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Ensure that 'hcloud' dependency is present on control host] **********************************************************************************************************
ok: [localhost -> 127.0.0.1]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Remove temporary SSH key 'ssh_key_tmp_qdalklg' from cloud (if any)] ***********************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Add SSH key 'ssh_key_tmp_qdalklg' to cloud] ***********************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Gather information about SSH key 'ssh_key_tmp_qdalklg'] ***********************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: ssh_key_names] *****************************************************************************************************************************************
ok: [localhost] => (item=None)
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Gather information about network zones] ***************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Extract network zone for server_location] *************************************************************************************************************
ok: [localhost] => (item=network_zone: eu-central)

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Gather information about networks] ********************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create a network 'postgres-cluster-network-eu-central'] ***********************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create a subnetwork in network 'postgres-cluster-network-eu-central'] *********************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Set variable: server_network] ****************************************************************************************************************************************
ok: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create or modify public firewall] *********************************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create or modify Postgres cluster firewall] ***********************************************************************************************************
changed: [localhost]

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create or modify server] ******************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Add server to network 'postgres-cluster-network-eu-central'] ******************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01)
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02)
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03)

TASK [vitabaks.autobase.cloud_resources : Hetzner Cloud: Create or modify volume] ******************************************************************************************************************************
changed: [localhost] => (item=vitabaks-pgcluster-pgnode01-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode02-storage)
changed: [localhost] => (item=vitabaks-pgcluster-pgnode03-storage)

TASK [vitabaks.autobase.cloud_resources : Server info] *********************************************************************************************************************************************************
ok: [localhost] => (item=vitabaks-pgcluster-pgnode01) => {
    "msg": {
        "id": "103980669",
        "image": "ubuntu-24.04",
        "name": "vitabaks-pgcluster-pgnode01",
        "private_ip": "10.0.1.1",
        "public_ip": "N/A",
        "type": "cx22",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode02) => {
    "msg": {
        "id": "103980815",
        "image": "ubuntu-24.04",
        "name": "vitabaks-pgcluster-pgnode02",
        "private_ip": "10.0.1.2",
        "public_ip": "N/A",
        "type": "cx22",
        "volume_size": "10 GB"
    }
}
ok: [localhost] => (item=vitabaks-pgcluster-pgnode03) => {
    "msg": {
        "id": "103980974",
        "image": "ubuntu-24.04",
        "name": "vitabaks-pgcluster-pgnode03",
        "private_ip": "10.0.1.3",
        "public_ip": "N/A",
        "type": "cx22",
        "volume_size": "10 GB"
    }
}
  • no public IP

passed

vitabaks avatar Jul 14 '25 10:07 vitabaks