0

I have an autoscaling group set up in my cloudformation template that spins up a single ec2 instance. In my userdata section of launchconfiguration, I execute the following statement:

sudo -u ec2-user git clone https://github.com/...git

I have to run this as an ec2-user, not as root. In the cloud-init-output.log, I get the following error: "fatal: unable to access 'https://github.com/...git/': Could not resolve host: github.com; Name or service not known"

Any suggestions as to how I can run this as ec2-user?

niketp
  • 409
  • 1
  • 9
  • 20
  • @jww This question is about writing Bash code within Cloudformation code. Can you really not understand that? – Alex Harvey Feb 23 '19 at 04:01
  • @Alex - Sorry, the site rules say the question is off-topic. Network and DNS configuration questions belong on another site in the [Stack Exchange network](https://stackexchange.com/sites) network. Maybe you can raise the issue on [Meta.SO](https://meta.stackoverflow.com/) and get the rules changed. Good luck. – jww Feb 23 '19 at 04:31
  • @jww, could you direct me to the line in the question where the OP asked how to configure the DNS? Because on my reading, they asked how to write code that would run a git clone as another user. – Alex Harvey Feb 23 '19 at 04:34
  • @Alex - *"Could not resolve host: github.com; Name or service not known"*. That's a network problem. And when you leave it on this site you get the useless developer-2-developer answers like below, that says clone another GitHub. The proper tools for the job are `ping` and `traceroute`. They will help isolate the problem. – jww Feb 23 '19 at 04:37
  • @jww, so what you mean is the answer required discussion of the network. Not the question. – Alex Harvey Feb 23 '19 at 04:39
  • @Alex - No. What I mean is network troubleshooting is better suited for a site like [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/). – jww Feb 23 '19 at 05:01
  • 1
    @jww, but you do understand that the OP didn't know it was a network problem. Otherwise they probably wouldn't be here asking a question in the first place. Yes? Perhaps read this: [Could we please be a bit nicer to new users?](https://meta.stackexchange.com/questions/9953/could-we-please-be-a-bit-nicer-to-new-users). – Alex Harvey Feb 23 '19 at 05:03
  • @Alex - I was nice. I left a comment and explained what Stack Overflow is for, and I directed them to a place to find a better home for the question. That's more than Stack Overflow does for new users. Stack Overflow leaves the to suffer. – jww Feb 23 '19 at 05:04
  • Seems to be a network issue to me. You need to make sure that your ec2 is able to connect to internet. Try running the git clone command directly from CLI. – Sushant Sonker Feb 22 '19 at 20:52
  • I believe it is a network issue as well. I set these commands earlier in my userdata script: `export http_proxy=$PROXY_ADDR export https_proxy=$PROXY_ADDR export no_proxy=169.254.169.254 export HTTP_PROXY=$PROXY_ADDR export HTTPS_PROXY=$PROXY_ADDR export NO_PROXY=169.254.169.25` PROXY_ADDR is the network for my company and it comes from the cloudformation template. – niketp Feb 22 '19 at 21:06

1 Answers1

2

The error message you are seeing is:

Could not resolve host: github.com; Name or service not known

That is a network connectivity issue. See e.g. this related Stack Overflow answer.

You also mention that:

I have to run this as an ec2-user, not as root.

You haven't said why, however, and in general, there is no reason not to use the root user to clone code from Github.

If you must run the command as the ec2-user, try:

cd /home/ec2-user
su ec2-user -c "git clone https://github.com/...git"

If you just need the root user to use a private key that belongs to another user:

GIT_SSH_COMMAND="ssh -i /home/ec2-user/.ssh/id_rsa" git clone git@github.com:....git

Otherwise, simply cloning the code via HTTPS as the root user will work fine (if you fix up the network problem).

jthill
  • 55,082
  • 5
  • 77
  • 137
Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • Hi Alex, thanks for the response. I have to run in as ec2-user because there is a python cgi-script in that repository that seems to not render. A similar ec2-instance cloned the repo as ec2-user and that cgi script renders fine. – niketp Feb 25 '19 at 20:37