I am using GitHub Actions, and trying to build and deploy my project using a self hosted runner. I have added the required SS_KEY in my Github repository secret and other secrets as well such as USER_ID and SERVER_IP.
I can manually doing SSH from the runner instance and make deployment without issues.
But I cant deploy the same from actions due to permission issue.
My actions.yaml
name: myproject
on:
push:
workflow_dispatch:
concurrency:
group: "${{ github.ref }}"
cancel-in-progress: true
permissions:
contents: read
packages: read
env:
USER_ID: "${{ secrets.USER_ID }}"
SS_KEY: "${{ secrets.SS_KEY }}"
SERVER_IP: "${{ secrets.SERVER_IP }}""
jobs:
dev-build:
runs-on:
- self-hosted
container:
image: ghcr.io/yepme/skanska:1.8
if: github.ref == 'refs/heads/feature-branch'
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- run: |
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -yqq ) &&
eval $(ssh-agent -s) &&
echo "$SS_KEY" | ssh-add - &&
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&
echo "$SS_KEY" > key.pem && chmod 400 key.pem &&
ansible-playbook deploy/deploy.yml -i hosts --extra-vars '{"project":"shopping","component":"customer"}' --tags "build"
- uses: actions/[email protected]
if: success()
with:
name: "${{ github.job }}"
path: build/build.tar.gz
dev-deploy:
needs: dev-build
runs-on:
- self-hosted
container:
image: ghcr.io/yepme/skanska:1.8
if: github.ref == 'refs/heads/feature-branch'
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
- run: |
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -yqq ) &&
eval $(ssh-agent -s) &&
echo "$SS_KEY" | ssh-add - &&
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&
echo "$SS_KEY" > key.pem && chmod 400 key.pem &&
pwd &&
ls -la &&
# getting error here
ssh -p 2069 $AZUREGID@$AZURE_DEVRULEENGINESERVERIP "echo $AZURE_DEVRULEENGINECONFIG > /tmp/config.ini; mkdir -p ~/.cassandra/.certs; echo $AZ_DEV_CASS_CERT > ~/.cassandra/.certs/dev_cass.cer.pem; echo $AZURE_DEV_CASS_KEY > ~/.cassandra/.certs/dev_cass.key.pem"
echo "[node]" > hosts &&
echo "$SERVER_IP ansible_ssh_port=2069 ansible_ssh_user=$USER_ID ansible_ssh_private_key_file=./key.pem" >> hosts &&
cat hosts > unauth_usage &&
ansible-playbook deploy/deploy.yml -i unauth_usage --extra-vars '{"project":"shopping","component":"customer","process":"customer_max","dir":"customer","env":"dev"}' --tags "unauth_monitor" &&
ansible-playbook deploy/deploy.yml -i hosts --extra-vars '{"project":"shopping","component":"customer","process":"customer_max","dir":"customer","env":"dev"}' --tags "deploy"
The error is
Warning: Permanently added '[***]:2069' (ECDSA) to the list of known hosts.
***@***: Permission denied (publickey).
Am I missing something?