aws user_data with ec2 instance, github actions runner ./config.sh file not running when --unattended flag is used

24 views Asked by At

I am trying to register my machine as a github actions runner in unattended mode using user_data. I am including the user_data in terraform

The machine spins up without issue and most of the commands run fine such as install docker, make directory etc

I am getting stuck when it comes to the user_data running the config.sh script as part of the machine connecting to github to be seen as a self-hosted runner

My user_data looks as below:

user_data = <<-EOF
  #!/bin/bash -xe

  sudo yum update -y
  sudo yum install docker -y
  sudo yum install git -y
  sudo yum install jq -y

  sudo systemctl start docker
  sudo systemctl enable docker

  echo "creating directory for runner"

  if [ ! -d "actions-runner" ]; then
    sudo mkdir actions-runner
  fi

  cd /actions-runner

  if [ ! -d "runner" ]; then
    sudo curl -O -L https://github.com/actions/runner/releases/download/v2.313.0/actions-runner-linux-x64-2.313.0.tar.gz
    sudo tar xzf ./actions-runner-linux-x64-2.313.0.tar.gz
  fi

sudo chmod -R +x .

  # Use variables in config.sh command
  
  sudo mkdir test_folder

./config.sh --unattended --url "https://My-org" --token "xxx" --runnergroup "test" --name "test_runner" --labels "tes_runner" --work "_work"
./run.sh
EOF

I've tried by creating a script and placing it on the machine to run, also tried download from s3 and run it but no joy.

It does create the actions-runner folder at root, and as part of the test create the test_folder as well.

When I run the ./config.sh command when connected to the machine manually, it runs fine with the parameters and connects to GitHub without issue

Any help appreciated.

0

There are 0 answers