4

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.

Tomas
  • 2,676
  • 5
  • 41
  • 51
  • As soon as I wrote it it downed on me (of course!) I also had some permissions problems there but unrelated to this question. If you want to write above as answer I will accept it – Tomas Sep 19 '17 at 10:23

1 Answers1

7

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 ]
Inian
  • 80,270
  • 14
  • 142
  • 161
  • 2
    Just FYI I ended up doing: `- [ /opt/cloud-init-scrips/whatever.sh ]` without specifying what command to use – Tomas Sep 19 '17 at 10:48