Ansible automation – Logging user-data script output for EC2

Date Posted: 06-10-2017

When you write ansible playbooks, you may want to log the user_data output of EC2 instance launch.

To achieve this, add these below codes at the top of your script

vi user_data.sh

#!/bin/bash -e
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
echo BEGIN
hostname
echo END

Once the instance is up, you can login and verify the log.

cat /var/log/user_data.log

BEGIN
server.pheonixsolutions.com
END

 

Leave a Reply