代码之家  ›  专栏  ›  技术社区  ›  Nishant Singh

无法在本地使用ansibe对克隆进行git

  •  1
  • Nishant Singh  · 技术社区  · 7 年前

    我正试图在本地系统上克隆一个git repo。我已经手动完成了,它工作得很好,但是当我试图通过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": []}
    

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

    3 回复  |  直到 7 年前
        1
  •  2
  •   VonC    7 年前

    有两个错误:

    • path '/home/nishant/superb-queue' already exists and is not an empty directory
      如果您已经手动克隆了repo,请确保在通过ansible再次尝试之前删除该克隆的存储库文件夹。
    • git@bitbucket.org: Permission denied (publickey).
      确保ansible使用与您相同的帐户运行,以便在 ~/.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 )

        2
  •  4
  •   techraf    7 年前

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

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

    添加 run_once: true 完成任务。

        3
  •  0
  •   user9857025    7 年前

    从你的问题来看,我认为你在使用公共回购,如果没有,那么你应该 key_file 您可能还需要添加一个用户。

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

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