canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
3k stars 885 forks source link

Bash option 'set -e' is ignored #5808

Open pschirch opened 1 month ago

pschirch commented 1 month ago

Bug report

You usually use set -e to exit a script on error. cloud-init status should be error now. But cloud-init continues and ends up with status done.

cloud-init status --long

status: done
extended_status: done
boot_status_code: enabled-by-generator
last_update: Thu, 01 Jan 1970 00:01:48 +0000
detail: DataSourceHetzner
errors: []
recoverable_errors: {}

Steps to reproduce the problem

#cloud-config
write_files:
  - owner: root:root
    path: /root/.cloud-init/some-script.sh
    content: |
      #!/bin/bash

      set -e

      a command that will fail

runcmd:
  - /bin/bash /root/.cloud-init/some-script.sh

Environment details

cloud-init logs

 /root/.cloud-init/some-script.sh: line 5: a: command not found
TheRealFalcon commented 1 month ago

@pschirch , I cannot reproduce this. Using the same version of Ubuntu, cloud-init, and your user data, I get:

# cloud-init status --wait --long
......status: error
extended_status: error - done
boot_status_code: enabled-by-generator
last_update: Thu, 01 Jan 1970 00:00:06 +0000
detail: DataSourceLXD
errors:
    - ('scripts_user', RuntimeError('Runparts: 1 failures (runcmd) in 1 attempted commands'))
recoverable_errors:
WARNING:
    - Failed to run module scripts_user (scripts in /var/lib/cloud/instance/scripts)
    - Running module scripts_user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed

Can you run cloud-init collect-logs on an affected instance and upload them?