简体   繁体   English

cloud-init 文件跳过 Github 注册

[英]Cloud-init File skip Github registration

I want to deploy my Github Repository with a terraform and a cloud-init file to aws.我想将我的 Github 存储库和一个 terraform 和一个 cloud-init 文件部署到 aws。 Iam doing this whole process with github actions.There they devilered me some commands to enter:我正在用 github 动作完成整个过程。他们给我一些命令输入:

#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.是来自 github 的注册。我必须输入 3 次回车键。 Now my Question is, how can i skip or tell my script, that he have to enter this key 3 times?现在我的问题是,我怎样才能跳过或告诉我的脚本,他必须输入这个密钥 3 次?

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 档案:

    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.我想要 cloud-init 文件超越 terraform apply 命令。

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.此命令中有 3 个步骤。 There you should enter the "Enter" Key在那里你应该输入“Enter”键

You can use the expect command to automate the process of entering the 3 keys.您可以使用 expect 命令自动执行输入 3 个密钥的过程。 You can add the following commands to your cloud-init file:您可以将以下命令添加到您的 cloud-init 文件中:

- 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. expect 命令将运行 ./config.sh 命令,并在提示“Press Enter to continue”消息时自动输入“Enter”键,输入 3 次。

Please note that this solution will work if the messages on the cloud-init file are the same.请注意,如果 cloud-init 文件中的消息相同,则此解决方案将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM