簡體   English   中英

無法使用ansible在本地git克隆

[英]unable to git clone on local using ansible

我正在嘗試在本地系統上克隆一個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上為空,我有正確的鍵。 不知道為什么會這樣

您正在多個主機目標上同時運行任務,每個目標都委派給本地主機,從而有效地相互競爭:

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

run_once: true添加到任務。

您有兩個錯誤:

  • path '/home/nishant/superb-queue' already exists and is not an empty directory
    如果您已經手動克隆了存儲庫,請確保先刪除該克隆的存儲庫文件夾,然后再通過Ansible再次嘗試。
  • git@bitbucket.org: Permission denied (publickey).
    確保使用與您的帳戶相同的帳戶運行Ansible,以便在~/.ssh使用相同的SSH密鑰。
    或定義正確的ansible.cfg

問題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

根據您的問題,我假設您使用的是公共倉庫,那么您應該已經添加了key_file並且可能還需要添加一個用戶。

請查看以下解決方案以獲取更多信息https://stackoverflow.com/a/39735848/9857025

讓我們知道是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM