I’m trying to get userdata outputs and errors into the system logs that are presented either through the gui or using
aws ec2 get-console-output
I’m having a hard time, has anyone gotten this to work?
I’ve tried solutions like this: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-log-user-data/
but it doesn’t seem to work for RHEL 7. I"ve also tried passing my commands to tty0 and ttyS0 with no luck
for example:
echo “testing system log with tty0” > tty0
echo “testing system log with ttyS0” > ttyS0
Still no luck.
I"ve noticed that the Amazon Linux ami does this automatically, but I have a client where we must use RHEL 7.x currently.
This is what I’ve used in past CloudFormation templates with RHEL7 AMIs:
#!/bin/bash
# set debug mode
set -x
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
This logs the userdata outputs in the user-data.log file.
In my experience, this has been due to the “quiet” grub command line parameter on RHEL 7. Try removing it and rebuild grub to see if it helps.
There’s a trick with grub…
#grub config taken from /etc/sysconfig/grub on RHEL7 AMI
cat > ${ROOTFS}/etc/default/grub << END
GRUB_TIMEOUT=0
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT=“console”
GRUB_CMDLINE_LINUX=“crashkernel=auto console=ttyS0,115200n8 console=tty0 net.ifnames=0 tsc=reliable clocksource=tsc”
GRUB_DISABLE_RECOVERY=“true”
END
Taken from this packer template
https://gist.github.com/snixon/5e8d37f16b17925f14d2c59b77589ead
That looks like a chroot install script, not a packer template? Those would typically be in JSON.
Oh sorry, yes, the packer template uses the ebs-surrogate builder to call that script. I should upload the actual template.json somewhere =)