action-ansible-playbook
action-ansible-playbook copied to clipboard
SSH Issues – a bit more documentation would be nice
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.
@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)
}
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
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.
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.
@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.
Don't forget to set the ssh user
I will gladly review PRs improving the documentation.
Always getting this error
This is my workflow
Solved this issue by creating a self hosted runner