无法使用ansible在本地进行git克隆
我试图在本地系统上克隆git repo。我已经手动完成了这项工作,效果很好,但当我试图通过ansible完成这项工作时,却没有成功 这是我的剧本:无法使用ansible在本地进行git克隆,git,ansible,Git,Ansible,我试图在本地系统上克隆git repo。我已经手动完成了这项工作,效果很好,但当我试图通过ansible完成这项工作时,却没有成功 这是我的剧本: --- - name: Create a directory on root file: path: "{{ local_home_dir }}/superb-queue" owner: "{{ local_user }}" group: "{{ local_user }}" state:
---
- name: Create a directory on root
file:
path: "{{ local_home_dir }}/superb-queue"
owner: "{{ local_user }}"
group: "{{ local_user }}"
state: directory
delegate_to: localhost
- name: Clone the bitbucket queue repo locally
git:
repo: git@bitbucket.org:superbhq/queue-main.git
dest: "{{ local_home_dir }}/superb-queue"
clone: yes
recursive: yes
force: yes
accept_hostkey: yes
version: master
key_file: "{{ local_home_dir }}/.ssh/id_rsa"
become_user: "{{ local_user }}"
delegate_to: localhost
我得到的错误是
ASK [deploy-queue-main : Clone the bitbucket queue repo locally] ******************************************************************************************************************************************
fatal: [10.0.3.219 -> localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin '' /home/nishant/superb-queue", "msg": "fatal: destination path '/home/nishant/superb-queue' already exists and is not an empty directory.", "rc": 128, "stderr": "fatal: destination path '/home/nishant/superb-queue' already exists and is not an empty directory.\n", "stderr_lines": ["fatal: destination path '/home/nishant/superb-queue' already exists and is not an empty directory."], "stdout": "", "stdout_lines": []}
fatal: [10.0.4.36 -> localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin '' /home/nishant/superb-queue", "msg": "Cloning into '/home/nishant/superb-queue'...\nWarning:********@bitbucket.org: Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "Cloning into '/home/nishant/superb-queue'...\nWarning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.\r\ngit@bitbucket.org: Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stderr_lines": ["Cloning into '/home/nishant/superb-queue'...", "Warning: Permanently added 'bitbucket.org,104.192.143.3' (RSA) to the list of known hosts.", "git@bitbucket.org: Permission denied (publickey).", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "", "stdout_lines": []}
本地系统上的目录是空的,我有正确的键。不确定为什么会发生这种情况根据您的问题,我假设您正在使用公共回购,如果不是,那么您应该添加
密钥文件
,并且您可能还需要添加一个用户
请查看以下解决方案以了解更多信息
让我们知道这是否有帮助。您有两个错误:
路径“/home/nishant/superfore queue”已存在,并且不是空目录
如果您已经手动克隆了repo,请确保在通过Ansible再次尝试之前删除该克隆的存储库文件夹git@bitbucket.org:权限被拒绝(公钥)。
确保Ansible使用与您相同的帐户运行,以便在~/.SSH
或者定义
这里,
dest
应该是克隆存储库的(不存在的)根文件夹(不是~
,而是~/myrepo
)您在多个主机目标上同时运行任务,每个目标都委托给本地主机,彼此之间有效地竞争:
将
run\u once:true
添加到任务中。对于A点:我正在克隆到一个新文件夹中,所以我有点困惑there@NishantSingh对于测试,您是否可以尝试使用force:yes
?使用force yes/no,目录被克隆为key_文件,但是关于文件的错误存在remains@NishantSingh在启动Ansible playbook之前,/home/nishant/superfore queue
不存在?我不是说“空”,我是说“不存在”@NishantSingh你能不先创建它就尝试一下吗?是的,我添加了密钥文件,这很有效。。但仍然是“味精”:致命:目标路径“/home/nishant/superfore queue”已存在,并且不是空目录。请在克隆之前清除该目录。克隆时,目录必须为空。完成后,您可以尝试删除“超级队列”并在“nishant”中克隆。让我知道这是否有效我喜欢这个解释(比我的答案好)+1.“这是我的剧本”ー 你发布的不是剧本,这是两个任务。请在发布更多问题之前阅读。
- name: Clone code repository
git: repo=example.com/repos/enterprise.git
dest=/home/user/enterprise
accept_hostkey=yes
force=yes
recursive=no
key_file={{ userhome }}/.ssh/id_rsa
depth={{ repo_depth }}
fatal: [10.0.3.219 -> localhost]: ...
fatal: [10.0.4.36 -> localhost]: ...