使用 ansible 将 git repo 拉到 vagrant box [英] Pulling git repo to a vagrant box using ansible
问题描述
大家好,我正在尝试通过 ansible 将一个 repo 从我的 github 拉到一个 vagrant box,参考 这个 github 问题.我已经从我的主机向 github 注册了一个 ssh.下面是剧本中我试图拉取的部分;
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"
安装 git 后,我已将公钥和私钥复制到框中,但在最后一步中我的配置失败.我无法提取 repo,而是收到以下错误;
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
我输入的地址有误吗?我试过 repo=ssh://git@github.com/myusername/project_foo_bar.git
但这也不会飞
Am I wrongly entering the address. I tried repo=ssh://git@github.com/myusername/project_foo_bar.git
but that too doesn't fly
推荐答案
您在 /home/projects/myproject
目录中初始化存储库,然后尝试将 github 存储库克隆到同一目录.
You init a repository in /home/projects/myproject
directory and then try to clone a github repo to the very same directory.
删除初始化任务,从框中删除 /home/projects/myproject
目录并再次运行您的剧本.
Remove init task, delete /home/projects/myproject
directory from the box and run your playbook again.
这篇关于使用 ansible 将 git repo 拉到 vagrant box的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!