Environment variable not recognizing database IP in Jelastic JPS deployment with N8N

I’m having trouble setting up N8N using a Jelastic JPS configuration file. The main issue is that the PostgreSQL database host IP isn’t being properly assigned to the environment variable.

The Problem:
I need to pass the postgres node IP to the DB_POSTGRESDB_HOST variable using ${nodes.sqldb[0].address}, but it seems like Jelastic can’t detect this variable during deployment. When I manually set this variable through the web interface after deployment, everything works fine.

What I’ve Tried:

DB_POSTGRESDB_HOST: ${nodes.sqldb[0].address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.first.address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.master.address}

Here’s my current JPS setup:

type: install
id: workflow-automation
version: 1.0
name: Workflow Automation Platform

globals:
  database_user: automation-${fn.random(1000)}
  database_pass: ${fn.password}
  secret_key: workflow${fn.password}

nodes:
- nodeType: nginx
  displayName: Proxy Server
  cloudlets: 16
  nodeGroup: lb
- image: n8nio/n8n:latest
  displayName: Automation Engine
  cloudlets: 16
  nodeGroup: app
  links: database:db
  env:
    N8N_BASIC_AUTH_ACTIVE: true
    N8N_BASIC_AUTH_USER: ${globals.database_user}
    N8N_BASIC_AUTH_PASSWORD: ${globals.database_pass}
    N8N_ENCRYPTION_KEY: ${globals.secret_key}
    DB_TYPE: postgresdb
    DB_POSTGRESDB_DATABASE: automation
    DB_POSTGRESDB_HOST: ${nodes.database[0].address}
    DB_POSTGRESDB_PORT: 5432
    DB_POSTGRESDB_USER: ${globals.database_user}
    DB_POSTGRESDB_PASSWORD: ${globals.database_pass}
- image: postgres:16.2
  cloudlets: 16
  nodeGroup: database
  displayName: Database Server
  env:
    POSTGRES_USER: ${globals.database_user}
    POSTGRES_PASSWORD: ${globals.database_pass}
    POSTGRES_DB: automation

Root Cause:
I think the issue is timing related. When the environment variables are being set, the PostgreSQL node hasn’t been created yet, so there’s no IP address to reference.

Has anyone dealt with this before? How can I dynamically assign the database IP after the nodes are fully deployed?

The nodeGroup reference mismatch is your problem. You’re defining the postgres container with nodeGroup: database but trying to access it with ${nodes.database[0].address} in the environment variables. Since you’re setting the env vars at the same node definition level, Jelastic processes them before the referenced nodes exist. I’ve had better luck using the onInstall actions block instead. Move your environment variable assignment to an onInstall script that runs after node creation but before service startup. Use jelastic environment.control.AddContainerEnvVars with your app nodeGroup as the target. This guarantees the database node exists and has an IP when the variable gets set. Also throw in a brief delay or health check to make sure postgres is actually responding before N8N tries to connect.

Had the same issue with multi-node Jelastic deployments. Your variable syntax is fine - it’s definitely a timing problem. Here’s what fixed it for me: use dependsOn in your JPS file so the app node waits for the database to fully initialize first. Also try setting startServiceOnCreation: false on the app node, then start it through onAfterServiceStart actions after the environment variables are set. Another trick - add a cmd action in onAfterDeploy to restart the N8N container once all nodes are confirmed running. The restart lets it grab the actual IP address instead of whatever placeholder it had before.

Try onAfterDeploy instead of setting it directly in env vars. Run a script that updates the env variable once all nodes are up. The jelastic environment.control.SetContainerEnvVars API call should handle this timing issue.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.