应用场景:自己搭建的 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