0

Hi all I am trying to pull a repo from my github to a vagrant box via ansible, refering this github issue. I have registered an ssh from my host with the github. And below is the part in the playbook where I'm trying to pull;

  - name: install git
    apt: name=git

  - name: create the ssh public key file
    copy: src=/home/user/.ssh/id_rsa.pub dest=/root/.ssh/id_rsa.pub mode=0644

  - name: create the ssh private key file
    copy: src=/home/user/.ssh/id_rsa dest=/root/.ssh/id_rsa mode=0600

  - name: setup git repo
    git: repo=git@github.com:myusername/project_foo_bar.git dest=/home/projects/myproject accept_hostkey=yes key_file="/root/.ssh/id_rsa"

After installing git I've copied my public and private keys to the box but my provisioning fails in the last step. I'm unable to pull the repo, instead get the below error;

TASK: [setup git repo] ******************************************************** 
failed: [default] => {"cmd": "/usr/bin/git ls-remote origin -h     refs/heads/master", "failed": true, "rc": 128}
stderr: fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

msg: fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

FATAL: all hosts have already failed -- aborting

Am I wrongly entering the address. I tried repo=ssh://git@github.com/myusername/project_foo_bar.git but that too doesn't fly

Afzal S.H.
  • 1,084
  • 2
  • 14
  • 27
  • why do you _init_ a repository in `/home/projects/myproject`? – Konstantin Jul 21 '15 at 06:56
  • @Alik I've just started with both ansible and vagrant. Assumed that would be required. Now I have that out and the error remain the same. Din think that would be the reason but thank you. – Afzal S.H. Jul 21 '15 at 07:00
  • have you removed `/home/projects/myproject` folder from the box? – Konstantin Jul 21 '15 at 07:19
  • @Alik What do you mean I don't need `- name: create a directory for projects file: path=/home/projects state=directory` and `- name: create a directory for our project file: path=/home/projects/myproject state=directory` too? I have them above. – Afzal S.H. Jul 21 '15 at 07:25
  • Does the directory `/home/projects/myproject` exist in your box? If yes, does it contain any files and folders (`.git` specifically)? If yes then remove it and run your ansible playbook again – Konstantin Jul 21 '15 at 07:30
  • thanks man now it works :). Please have it as an answer so I could accept. Thanx. – Afzal S.H. Jul 21 '15 at 07:38

1 Answers1

1

You init a repository in /home/projects/myproject directory and then try to clone a github repo to the very same directory.

Remove init task, delete /home/projects/myproject directory from the box and run your playbook again.

Konstantin
  • 24,271
  • 5
  • 48
  • 65