前提
- ssh forward agent によってリモートでローカルの鍵を使用している
- git module の
become: true
にしたところこのエラーが発生した(外すと通常通りcloneできる)。
対応前
エラー発生時のコード
ansible.cfg
[ssh_connection]
ssh_args = -o ForwardAgent=yes
gitclone.yml
---
- hosts: all
tasks:
- name: Install git
become: true
apt:
name: git
- name: Clone
git: >
repo=<GIT_REPO>
dest="<DIR>"
accept_hostkey=true
become: true
以下のようなエラーが起こる
error
Cloning into '<DIR>'...
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
対応後
ansible.cfg
に sudo_flags
の設定を加えると動作する。
ansible.cfg
[defaults]
transport = ssh
sudo_flags = -HEs
[ssh_connection]
ssh_args = -o ForwardAgent=yes
参考
Ansible и Git Permission denied (publickey) в Git Clone - Qaru