Home > OS >  Cloud-init File skip Github registration
Cloud-init File skip Github registration

Time:01-24

I want to deploy my Github Repository with a terraform and a cloud-init file to aws. Iam doing this whole process with github actions.There they devilered me some commands to enter:

#cloud-config
runcmd:
- curl -o actions-runner-linux-x64-2.300.2.tar.gz -L https://github.com/actions/runner/releases/download/v2.300.2/actions-runner-linux-x64-2.300.2.tar.gz
- echo ed5bf2799c1ef7b2dd607df66e6b676dff8c44fb359c6fedc9ebf7db53339f0c  actions-runner-linux-x64-2.300.2.tar.gz" | shasum -a 256 -c
- tar xzf ./actions-runner-linux-x64-2.300.2.tar.gz
- ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA

is a registration from github. There i have to enter 3 times the enter key. Now my Question is, how can i skip or tell my script, that he have to enter this key 3 times?

Whole Cloud init File:

#cloud-config
runcmd:
- mkdir react
- cd react
- curl -o actions-runner-linux-x64-2.300.2.tar.gz -Lhttps://github.com/actions/runner/releases/download/v2.300.2/actions-runner-linux-x64-2.300.2.tar.gz
- echo 
ed5bf2799c1ef7b2dd607df66e6b676dff8c44fb359c6fedc9ebf7db53339f0c
actions-runner-linux-x64-2.300.2.tar.gz" | shasum -a 256 -c
- tar xzf ./actions-runner-linux-x64-2.300.2.tar.gz
- ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA
- sudo ./svc.sh install
- sudo ./svc.sh start
- sudo apt install nginx
- cd _work
- cd react-deploy-aws
- cd react-deploy-aws
- cd /etc/nginx/sites-available
- sudo rm default
- echo "server {listen 80 default_server;server_name _;location / 
{root
/home/ubuntu/react/_work/react-deploy-aws/react-deploy- 
aws/build;try_files
\$uri /index.html;}}" | sudo tee /etc/nginx/sites-available/default
- sudo service nginx restart
- sudo chmod  x /home
- sudo chmod  x /home/ubuntu
- sudo chmod  x /home/ubuntu/react
- sudo chmod  x /home/ubuntu/react/_work
- sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws
- sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws/react- 
  deploy-aws
- sudo chmod  x /home/ubuntu/react/_work/react-deploy-aws/build

terraform file:

    terraform {
        required_providers {
         aws = {
      source = "hashicorp/aws"
      version = "~> 4.16"
    }
  }
  required_version = ">= 1.2.0"
} provider "aws" {
  region = "us-east-1b"
} data "template_file" "nginx" {
  template = file("./cloud-init.yaml")
} resource "aws_security_group" "gradebook" {
  name        = "gradebook"
  description = "Security group for Gradebook server"   ingress {
    protocol   = "tcp"
    from_port  = 22
    to_port    = 22
    cidr_blocks = ["0.0.0.0/0"]
  }   ingress {
    protocol   = "tcp"
    from_port  = 80
    to_port    = 80
    cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
    protocol   = "tcp"
    from_port  = 443
    to_port    = 443
    cidr_blocks = ["0.0.0.0/0"]
  }   egress {
    protocol   = "-1"
    from_port  = 0
    to_port    = 0
    cidr_blocks = ["0.0.0.0/0"]
  }
} resource "aws_instance" "web_server" {
  ami          = "ami-0574da719dca65348"
  instance_type = "t2.small"
  vpc_security_group_ids = [aws_security_group.gradebook.id]
  user_data = data.template_file.nginx.rendered   tags = {
    Name = "GradebookWebServer"
  }
}

I dont have any clue how to solve this.

I want, that the cloud-init file is surpassing the terraform apply command.

I want, that the registration part which takes place in this command:

./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA

can be skipped. There are 3 steps within this command. There you should enter the "Enter" Key

CodePudding user response:

You can use the expect command to automate the process of entering the 3 keys. You can add the following commands to your cloud-init file:

- apt-get update && apt-get install -y expect
- expect -c "spawn ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX; expect \"Press Enter to continue\"; send \"\r\"; expect \"Press Enter to continue\"; send \"\r\"; expect \"Press Enter to continue\"; send \"\r\"; interact"

The expect command will run the ./config.sh command, and automatically enter the "Enter" key when prompted with the "Press Enter to continue" message, 3 times.

Please note that this solution will work if the messages on the cloud-init file are the same.

  • Related