【发布时间】:2021-09-28 03:44:06
【问题描述】:
作为更大剧本的一部分,我尝试在 Ansible 任务中克隆一个 repo,但它失败了
git@github.com: Permission denied (publickey).。
手动执行相同的操作。怎么了?
我的剧本的最小示例:
---
- 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
库存文件:
[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
结果:
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
我意识到 ansible 实际上正在运行 git ls-remote '' -h refs/heads/main。
documentation on ls-remote 不太冗长。
【问题讨论】:
-
您是否以同一用户身份运行 playbook 和手动测试?
-
嗯,我想我知道。有没有办法记录这些信息?
-
你的意思是当你发出两个命令时你不确定你登录的是哪个用户? (例如
git clone ...vsansible-playbook ...) -
我对此很确定,只是不确定 Ansible 是否以及何时将用户更改为 root 以在 ansible.cfg 中使用 become=true 进行操作。我刚刚尝试了 become=false 并得到了同样的错误......所以不是这样。
-
那么当你在 Ansible 和手动执行命令时,你没有使用相同的键。