I am trying to clone a git repo on my local system. I have done this manually and it works fine, but when I try to do it via Ansible, it doesn't work out
Here is my play:
---
- 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: [email protected]: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
The error I get is:
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\[email protected]: 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.", "[email protected]: 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": []}
The directory is empty on the localsystem, and I have the right keys. Not sure why this is happening
You are running the task concurrently on multiple host targets, each of which is delegating to the local host, effectively competing with each other:
fatal: [10.0.3.219 -> localhost]: ... fatal: [10.0.4.36 -> localhost]: ...
Add run_once: true to the task.
You have two errors:
path '/home/nishant/superb-queue' already exists and is not an empty directory[email protected]: Permission denied (publickey).~/.ssh.As mentioned in issue 5722, try:
- 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 }}
Here, dest should be the (non-existing) root folder of the cloned repository (not ~, but ~/myrepo).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With