As part of a larger playbook I try to clone a repo in an Ansible task and it fails with
git@github.com: Permission denied (publickey).
.
Doing the same manually works. What is wrong?
Minimal Example of my playbook:
---
- hosts: all
tasks:
- name: Ensure dotfiles repository is cloned locally.
git:
repo: "git@github.com:geerlingguy/dotfiles.git"
dest: "~/devops/macsetup/dotfiles"
key_file: /Users/myUser/.ssh/id_ed25519
version: "main"
accept_hostkey: true
become: false
Inventory file:
[all]
127.0.0.1 ansible_connection=local
ansible.cfg:
[defaults]
nocows = true
roles_path = ./roles
inventory = inventory
become = true
stdout_callback = yaml
log_path = ~/Desktop/ansibleLog_test.txt
Result:
TASK [Ensure dotfiles repository is cloned locally.] ***************************************************************************************
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
File "/var/folders/3v/qk0n7z693jv2pz23cy99q7_m0000gn/T/ansible_git_payload_TeGqRk/ansible_git_payload.zip/ansible/modules/git.py", line 499, in clone
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
fatal: [127.0.0.1]: FAILED! => changed=false
cmd: /usr/bin/git ls-remote '' -h refs/heads/main
invocation:
module_args:
accept_hostkey: true
archive: null
archive_prefix: null
bare: false
clone: true
depth: null
dest: /Users/myUser/devops/macsetup/dotfiles
executable: null
force: false
gpg_whitelist: []
key_file: /Users/myUser/.ssh/id_ed25519
recursive: true
reference: null
refspec: null
remote: origin
repo: git@github.com:geerlingguy/dotfiles.git
separate_git_dir: null
single_branch: false
ssh_opts: null
track_submodules: false
umask: null
update: true
verify_commit: false
version: main
msg: ''
rc: 128
stderr: |-
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
PLAY RECAP ***************************************************************************************
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
I realized that ansible is actually running git ls-remote '' -h refs/heads/main
.
The documentation on ls-remote
is not too verbose.