应用场景:自己搭建的 github runner,要使用这个 runner 去控制另一台机器,去做事情。
准备
- 把部署 github runner 的这台机器的 ssh public key 使用
ssh-copy-id复制到要 ssh 登录到的目标机器 - 部署 github runner 的这台机器的 ssh private key 添加到 github 的 secrets 里,在 actions 里要使用这个 private key
编写 ci.yml
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
# 自己搭建的 runner 的 label
runs-on: integration
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Run a command remotely on target host
uses: docker://evaneos/ssh-action:0.1.0
with:
hosts: target host ip
user: root
private_key: ${{ secrets.PRIVATE_SSH_KEY_INTEGRATION_RUNNER }}
#knock_sequence: ${{ secrets.KNOCK_SEQUENCE }}
commands: |
echo "I can run..."
echo "...multiple commands"
pwd
who
job 根据 runs-on 指定的 label 选择 runner

该博客介绍了如何配置和使用自建的GithubRunner通过SSH连接到另一台目标机器,并在上面执行命令。首先,将源机器的SSH公钥复制到目标机器,然后将私钥添加到Github Secrets中。接着,在ci.yml文件中定义作业,指定runner标签并使用ssh-action Docker镜像执行远程命令。提供的示例展示了如何运行多个命令,如显示当前目录和用户信息。
368

被折叠的 条评论
为什么被折叠?



