如何在合适的git模块中使用远程机器的SSH密钥 [英] How do I use remote machine's SSH keys in ansible git module

查看:209
本文介绍了如何在合适的git模块中使用远程机器的SSH密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让Ansible配置远程机器,并且我希望远程机器使用自己的密钥进行设置,并且能够从Bitbucket中克隆git存储库。

I've been trying to get Ansible to provision a remote machine, and I want the remote machine to be set up with its own keys, and have the ability to clone git repositories from Bitbucket.

用户已设置,拥有自己的id_rsa.pub,并且该密钥已通过bitbucket注册。

The user is set up, has its own id_rsa.pub, and the key has been registered with bitbucket.

但是,当我使用Ansible Git模块,它看起来像模块总是尝试使用运行剧本的机器上的密钥。

But, when I use the Ansible Git module, it looks like the module always tries to use the keys from the machine running the playbook.

如何让git模块使用来自远程机器的id_rsa.pub?

How do I get the git module to use the id_rsa.pub from the remote machine?

相关任务是这样的:

- name: be sure prom-king has an up-to-date clone of its own repository
  git:
    repo: "ssh://ddcrnd@bitbucket.org/prom-king.git"
    dest: /home/promking/prom-king
    accept_hostkey: yes
    clone: yes
    key_file: /home/promking/.ssh/id_rsa.pub
    update: yes

相关库存为此目录

# inventory file for use with the vagrant box in the testing directory.
[prom-king]
192.168.168.192 ansible_ssh_host=127.0.0.1 ansible_sudo=true ansible_connection=ssh  ansible_ssh_port=2222 ansible_ssh_user=vagrant ansible_ssh_private_key_file=testing/.vagrant/machines/default/virtualbox/private_key


推荐答案

这是我从Github上使用密钥文件集远程服务器。如果 git keyfile 参数不起作用,那么您的playbook有些问题:

This is how I deploy from Github using a key file set on the remote server. If the keyfile parameter for git doesn't work then something is wrong with your playbook:

- name: Creates .ssh directory for root
  sudo: yes
  file: path=/root/.ssh state=directory

# This public key is set on Github repo Settings under "Deploy keys"
- name: Upload the private key used for Github cloning
  sudo: yes
  copy: src=keys/github dest=/root/.ssh/github

- name: Correct SSH deploy key permissions
  sudo: yes
  file: dest=/root/.ssh/github mode=0600

- name: Deploy site files from Github repository
  sudo: yes
  git:
    repo: git@github.com:miohtama/foobar.git
    dest: /srv/django/foobar
    key_file: /root/.ssh/github
    accept_hostkey: yes
    force: yes

这篇关于如何在合适的git模块中使用远程机器的SSH密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆