I am trying to bootstrap a Centos7 EC2 instance (ami-02eac2c0129f6376b) with bash user-data. Because it runs as root and I need to create a lot of things as the centos user, I use sudo -Hu centos <cmd>
many times. Each call introduces a 25 second delay. I have hundreds. What can I do to speed this up?
This is a known issue, but I cannot find any solutions.
I have tried:
- Add and
/etc/hosts
entry for my hostname
printf "\n127.0.0.1 %s %s\n" "$(hostname -f)" "$(hostname -s)" | tee -a /etc/hosts
- Remove myhostname from /etc/nsswitch.conf
sed -Ei 's/\s*myhostname//' /etc/nsswitch.conf
These delays are EXTREMELY painful because I am currently in the Trial and Error phase of building out new user-data scripts.
What can I do?
sudo
takes 25 seconds to make the call to the command.dig $(hostname)
work (return the instance's internal IP) anddig -x z.z.z.z
(z.z.z.z = instance's private IP) work (return the hostname) or do they time out or return an error? IIRC sudo tries to look up the machine's IP... 25 sec seems like a very long time if this is the problem, but this is the only idea I have.