LoginSignup
1
1

More than 5 years have passed since last update.

Ansible の git module が "Permission denied (publickey)." となった

Posted at

前提

  • 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.cfgsudo_flagsの設定を加えると動作する。

ansible.cfg
[defaults]
transport = ssh
sudo_flags = -HEs

[ssh_connection]
ssh_args = -o ForwardAgent=yes

参考

Ansible и Git Permission denied (publickey) в Git Clone - Qaru

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1