Home > database >  DigitalOcean API cloud-config - install Node v14
DigitalOcean API cloud-config - install Node v14

Time:02-14

I want to invoke Digital Ocean create droplet API to create a droplet with NodeJS v14 installed immediately. I invoked the API, get the IP, log in with SSH, but nothing is installed. Not sure what I am doing wrong or how to even debug it.

My API request:

curl --location --request POST 'https://api.digitalocean.com/v2/droplets' \
--header 'Authorization: Bearer $TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "names": [
    "test"
  ],
  "region": "nyc3",
  "size": "s-1vcpu-1gb",
  "image": "ubuntu-21-10-x64",
  "ssh_keys": [
    "my-key-fingerprint"
  ],
  "backups": false,
  "ipv6": true,
  "user_data": "#cloud-config\n\npackage_update: true\npackage_upgrade: false\npackage_reboot_if_required: false\n\nruncmd:\n  - '\''curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash'\''\n  - '\''source .bashrc'\''\n  - '\''nvm install v14.19.0'\''",
  "private_networking": null,
  "volumes": null,
  "tags": [
    "test"
  ]
}'

If I enter the 3 following thing manually in the ssh shell then it installs the Node just fine:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source .bashrc
nvm install v14.19.0

CodePudding user response:

You should check the Droplet's logs to determine what happened:

more /var/log/cloud-init-output.log 

For your script:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

=> Downloading nvm from git to '/.nvm'

=> Compressing and cleaning up git repository

=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
   OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
/var/lib/cloud/instance/scripts/runcmd: 3: source: not found
/var/lib/cloud/instance/scripts/runcmd: 4: nvm: not found
2022-02-13 17:57:03,777 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2022-02-13 17:57:03,778 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed
  • Related