【问题标题】:Unable to perform "git clone" on local system using Ansible无法使用 ansible 在本地进行 git clone
【发布时间】:2018-06-15 04:40:39
【问题描述】:

我正在尝试在我的本地系统上克隆一个 git 存储库。我已经手动完成了,它工作正常,但是当我尝试通过 ansible 完成它时,它不起作用

这是我的剧本:

---
  - 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": []}

本地系统上的目录是空的,我有正确的键。不知道为什么会这样

【问题讨论】:

标签: git ansible


【解决方案1】:

您正在多个主机目标上同时运行任务,每个目标都委派给本地主机,从而有效地相互竞争:

fatal: [10.0.3.219 -> localhost]: ...
fatal: [10.0.4.36 -> localhost]: ...

run_once: true 添加到任务中。

【讨论】:

  • 我喜欢这个解释(比我的回答更好)+1。
【解决方案2】:

你有两个错误:

  • path '/home/nishant/superb-queue' already exists and is not an empty directory
    如果您已经手动克隆了您的存储库,请确保在通过 Ansible 再次尝试之前删除该克隆的存储库文件夹。
  • git@bitbucket.org: Permission denied (publickey).
    确保 Ansible 使用与您相同的帐户运行,以便在 ~/.ssh 中使用相同的 SSH 密钥。
    或定义right ansible.cfg

如提到in issue 5722,试试:

- 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 }}

这里,dest 应该是克隆存储库的(不存在的)根文件夹(不是~,而是~/myrepo

【讨论】:

  • 对于A点:我正在克隆到一个新文件夹,所以我有点困惑
  • @NishantSingh 进行测试,你可以试试force: yes吗?
  • 强制是/否,目录被克隆为key_file,但关于文件存在的错误仍然存​​在
  • @NishantSingh 和 /home/nishant/superb-queue 在您启动 Ansible playbook 之前不存在?我不是说“空”,我是说“不存在”
  • @NishantSingh 你可以尝试而不先创建它吗?
【解决方案3】:

根据您的问题,我假设您正在使用公共回购,如果没有,那么您应该添加 key_file 并且您可能还需要添加用户。

请查看以下解决方案以获取更多信息 https://stackoverflow.com/a/39735848/9857025

如果这有帮助,请告诉我们。

【讨论】:

  • 是的,我添加了密钥文件并且有效.. 但仍然 "msg": "fatal: destination path '/home/nishant/superb-queue' 已经存在并且不是空目录.
  • 克隆前清除目录。克隆时目录必须为空。一旦完成,你就可以开始了
  • 尝试删除“superb-queue”并克隆到“nishant”中。让我知道这是否有效
猜你喜欢
  • 2022-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多