This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 573
Amazon Linux AMI
Chin Huang edited this page Nov 24, 2013
·
3 revisions
Amazon Linux AMIs are set
to require tty when sudo'ing, which causes problems when Vagrant tries
to do things like setup the rsync folder. In order to get around this
you can send aws user_data
to populate the cloud init config and change this
for the ec2-user when the instance is created:
aws.user_data = "#!/bin/bash\necho 'Defaults:ec2-user !requiretty' > /etc/sudoers.d/999-vagrant-cloud-init-requiretty && chmod 440 /etc/sudoers.d/999-vagrant-cloud-init-requiretty\nyum install -y puppet\n"
The user_data
script is executed late in the boot up process. When Vagrant sees SSH is available and attempts a sudo command, this script likely has not executed yet. As a work around, this example Jenkins job script retries the vagrant command:
#!/bin/bash
export AWS_ACCESS_KEY=CHANGEIT
export AWS_SECRET_KEY=CHANGEIT
sudo_unavailable() {
errorOutput=$WORKSPACE/vagrant.err
vagrant provision 2>$errorOutput
exitStatus=$?
cat $errorOutput
grep -q 'must have a tty to run sudo' $errorOutput
}
set -x
cd $WORKSPACE/virtual-machine
vagrant destroy --force
vagrant up --provider=aws --no-provision
count=0
while sudo_unavailable ; do
sleep 30
let count++
if [ $count -gt 4 ]; then
vagrant destroy --force
exit 1
fi
done
if [ $exitStatus = 0 ]; then
vagrant destroy --force
fi
exit $exitStatus