23

Where does output from cloud-init (automatically runs scripts when starting up a virtual machine in the cloud, for example at Amazon EC2) go? I would like to know that my initialization scripts executed successfully.

There is a /var/log/cloud-init.log file, but it seems to contain only partial output (namely from the SSH key initialization).

8 Answers 8

25

Since cloud-init 0.7.5 (released on Apr 1 2014), all output from cloud-init is captured by default to /var/log/cloud-init-output.log. This default logging configuration was added in a commit from Jan 14 2014:

# this tells cloud-init to redirect its stdout and stderr to
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
# there without needing to look on the console.
output: {all: '| tee -a /var/log/cloud-init-output.log'}

To add support for previous versions of cloud-init, you can manually add this configuration manually to your Cloud Config Data.

1
  • Note: One possible reason why you are not seeing the log output is that your user-data scripts are not actually being run. When following the cloud-init QEMU tutorial, I found that it wasn't applying subsequent changes to my user-data file. But when I initialised a new VM with multipass as described in the docs for local testing, I could see the output in the logs as expected. Similarly when deploying to an Azure VM, I had to destroy and re-create it to see the output from new commands in user-data.
    – daviewales
    Nov 1, 2023 at 0:46
6

The log is stored in systemd:

journalctl -u cloud-final
2
  • 1
    Welcome to Stackexchange, and thanks for your contribution. However, the question was asked ten years ago before systemd was widely used (or even before it existed). Even when systemd is used, I am not sure if your answer is correct. cloudinit documentation says something else. Feb 24, 2021 at 9:48
  • I just spun up an Ubuntu VM in Azure, and stdout from my cloud-init user-script runcmd block appears both in /var/log/cloud-init-output.log and in journalctl -u cloud-final. So this answer is valid, if not the officially documented log location.
    – daviewales
    Nov 1, 2023 at 0:39
3

I couldn't find way a "native" way for doing that. Before passing the script to cloud-init, I've simply (automatically) appended a >> /tmp/init-script-log 2>&1 to each line of the script, to forward stout and stderr to a file.

1
  • 1
    As Valko pointed out, neither /var/log/cloud-init.log nor /var/log/cloud-init-output.log captures output from user-data scripts. Roberto's solution here answers that concern. Another way I've seen this done is to preamble your user-data script to send all output to syslog with exec 1> >(logger -s -t "WhateverNameYouWantToMakeSiftingLogMessagerEasier") 2>&1 Jan 29, 2018 at 17:00
2

On the Centos 7 AMI I am using, the output of my user data script is in /var/log/cloud-init-output.log.

1

On my EC2 box (running the Amazon Linux AMI) it's stored in /var/log/cloud-init.log

1
  • 2
    Thanks, but it doesn't seem to contain output from user scripts.
    – Make Mark
    Feb 19, 2011 at 7:24
0

I've found log output in /var/log/messages (CentOS7 AWS AMI)

0

SystemD vote for me when trying to find logs in CentOs7 when /var/log/cloud-init-output.log is not present. journalctl -u cloud-final

-5

First of all let me congratulate you on using cloud-init, it's a quite amazing tool!

There's no way yet to setup a log level but by default cloud-init will run with DEBUG enabled.

It's still in heavy development, I expect it to be a lot better by the release of Ubuntu Natty

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .