Updating SSH Address

Sometimes i have to restart my amazon EC2 instance, and then it gives me a dynamic IP address. This means 2 things.

  1. I need to update CloudFlare “IP Access Rules” to allow the new IP to not be blocked for my domain protection

  2. I need to update the SSH Ip/hostname in the n8n credential area so all my SSH nodes in all the workflows can use the new IP when trying to execute.

  3. Im currently in the process of using the CloudFlare API to be able to update rules (just need a script to run when the box reboots to trigger this new n8n workflow.

  4. No idea how to update this automatically.

Thoughts?

That is an interesting one, The only bit that may be tricky is changing the n8n credentials automatically but it looks like you can use expressions for the hostname. I think what I would do is have n8n update an env variable as part of the API update calls and use that or store it somewhere else like a local file and just read the file at the start of the workflow to get the IP to use.

The other option would be to just get an elastic IP so your EC2 instance always has the same IP then it doesn’t matter.

1 Like

yeah then i have to pay for it :wink: but indeed is totally the correct thing to do, lol

the expression thing is interesting its only the hostname I need to update.

2 Likes

As a quick and ugly test… For your credentials you can do this…

image

That will then give you…

image

and in your workflow you can use a Set or whatever you want to set your IP

image

Then it is just a case of using the SSH node like normal.

image

So this then gives something that looks like this…
image

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "command": "ls"
      },
      "name": "SSH",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [
        520,
        300
      ],
      "credentials": {
        "sshPassword": {
          "id": "11",
          "name": "SSH"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "hostname",
              "value": "10.0.12.91"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        380,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "SSH",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

That Set node could be replaced with something to query a database, read a local file or do anything to pull the IP from where ever you store it.

1 Like

interesting, ill have a go and get back to you
cheers

1 Like