Knife ec2 server create - centos7 ami-61bbf104 - sudo - requiretty


#1

Hello,

When trying to create an ec2 instance using “knife ec2 server create …” with centos7 ami-61bbf104, I run into the sudo requiretty issue.

If anyone else has run into this, may I know how you have overcome?

Thanks
Naga


#2

How can I make knife do this for centos7?

Change this line in /etc/sudoers …

Defaults requiretty

To this …

# Defaults requiretty

That needs to happen as part of the ec2 instance creation/setup, else all sudo commands in ec2’s user_data_file fail with the message …

sudo: sorry, you must have a tty to run sudo

It is kind of a Catch22 or Chicken/Egg issue, in the sense trying to edit /etc/sudoers from outside the ec2 instance requires sudo access, and that cannot work w/out access to a terminal, and that defeats total automation.

BTW, no issue with Ubuntu, this is a RHEL/CentOS specific issue.

Is there a way to overcome, other than creating custom ami in which the line in /etc/sudoers is commented out?

Thanks
Naga


#3

When you use the bootstrap command you need to pass in a userdata script to
make that change before Chef runs. A userdata script that does an inplace
sed on /etc/sudoers will make the change you need.

You can pass the userdata script to knife ec2 server create using the
–user-data flag