Obviously I am doing something wrong here.
Cloud init script /etc/cloud/cloud.cfg
...
runcmd:
- [ sh, /opt/cloud-init-scripts/whatever.sh ]
The script /opt/cloud-init-scripts/whatever.sh
#!/bin/bash
...
. /home/ubuntu/third-party/script.sh --silent
Third party script /home/ubuntu/third-party/script.sh
#!/usr/bin/env bash
function some_function() {
...
Error I am getting in /var/log/cloud-init-output.log
/opt/cloud-init-scripts/whatever.sh: 3: /home/ubuntu/third-party/script.sh: Syntax error: "(" unexpected
I must be missing something obvious here. I tried using source
, .
and sh
when calling the third party script, tried changing shebangs everywhere but no success.
If I run the same command from command line it works.
You have specified sh
shell under runcmd
, but have she-bang set to bash
. The latter does not matter because if you run as sh /opt/cloud-init-scripts/whatever.sh
it will be run with sh shell. I guess you are probably using a non POSIX
shell feature which is incompatible with the sh
shell.
Or alternatively if your intention is to run the script in bash
shell, change the runCmd
in cloud-init
script to
runcmd:
- [ bash, /opt/cloud-init-scripts/whatever.sh ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With