Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH Issues – a bit more documentation would be nice #36

Open
vardumper opened this issue Oct 31, 2021 · 9 comments
Open

SSH Issues – a bit more documentation would be nice #36

vardumper opened this issue Oct 31, 2021 · 9 comments

Comments

@vardumper
Copy link

In order to make sure ansible has access to the boxes, I needed to remove the following line form my inventory file. Also I had to comment out the known_hosts setting.

I had the line in all:vars section

[all:vars]
ansible_ssh_private_key_file = ~/.ssh/id_rsa

After removing it, the playbook action could connect.

@clincha
Copy link
Contributor

clincha commented Oct 14, 2022

@vardumper agree it would be nice to have some documentation advising against setting the ansible_ssh_private_key_file value in the README. I'm not the best at node.js but it looks like the key is copied to a file called ".ansible_key" so you might be able to set ansible_ssh_private_key_file to that but easier to just omit it.

if (key) {
    const keyFile = ".ansible_key"
    fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
    core.saveState("keyFile", keyFile)
    cmd.push("--key-file")
    cmd.push(keyFile)
}

@MasteringBOX
Copy link

MasteringBOX commented Feb 25, 2023

EDIT: I solved it

I can't connect :/ I tried both suggestions and I got a permission denied error. I stored the private key string in an action secret and added it to the "key" variable. Is there anything I'm missing?

name: Deploy
on:
  push:
    branches: [ main ]
  workflow_dispatch:
 
jobs:
  deploy_code:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        
      - name: Run Ansible playbook
        uses: dawidd6/[email protected]
        with:
          playbook: ansible/deploy.yml
          key: ${{secrets.ANSIBLE_PRIVATE_KEY}} 
          inventory: |
            [exampleserver]
            example ansible_host=example.com ip=55.555.55.55 ansible_port=5555 ansible_ssh_user=example

@jozef-valko
Copy link

EDIT: I solved it

@MasteringBOX could you please elaborate more how you have fixed this? I'm facing the similar issue, looks like action is ignoring the value of key parameter.

@MasteringBOX
Copy link

MasteringBOX commented Mar 14, 2023

Hi @jozef-valko,

I don't fully remember, it was something silly.
Try adding your key to a secret called exactly SECRET_SSH_KEY.
I was using
key: ${{secrets.ANSIBLE_PRIVATE_KEY}}
and while I was desperately trying things I added the key to a new secret called SECRET_SSH_KEY and it worked.
So try creating that action secret with your secret key contents and changing the key value to:
key: ${{secrets.SECRET_SSH_KEY}}
But it may have been something else. Let me know if that works!

By the way, after configuring this I ended up using Github actions directly, they are pretty straightforward and they will deploy faster.

@jozef-valko
Copy link

@MasteringBOX I made it work, it was issue on my side with SSH keys and config. After generating new SSH keypair and setting parameters correctly:

- name: deploy stuff
   uses: dawidd6/action-ansible-playbook@v2
   with:
   playbook: deploy.yaml
   key: ${{ secrets.SSH_KEY }}
   options: |
     --user ssh_user
     --ssh-extra-args "-o StrictHostKeyChecking=no"

and setting --ssh-extra-args "-o StrictHostKeyChecking=no" GH action was able to connect to machines successfully.

@port19x
Copy link

port19x commented Jul 31, 2023

Don't forget to set the ssh user

@dawidd6
Copy link
Owner

dawidd6 commented Jan 5, 2024

I will gladly review PRs improving the documentation.

@arnabnath180
Copy link

arnabnath180 commented Jan 21, 2024

Screenshot from 2024-01-21 11-46-00
Always getting this error
This is my workflow
Screenshot from 2024-01-21 12-48-40

@arnabnath180
Copy link

Solved this issue by creating a self hosted runner

mblomdahl-bot added a commit to OwnTube-tv/minio-microk8s-ansible that referenced this issue Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants