gpt4 book ai didi

git - 如何在 ansible git 模块中使用远程机器的 SSH key

转载 作者:IT王子 更新时间:2023-10-29 01:26:45 24 4
gpt4 key购买 nike

我一直在尝试让 Ansible 提供一台远程机器,我希望远程机器设置有自己的 key ,并且能够从 Bitbucket 克隆 git 存储库。

用户已设置,拥有自己的id_rsa.pub, key 已注册到bitbucket。

但是,当我使用 Ansible Git 模块时,该模块似乎总是尝试使用运行 playbook 的机器上的 key 。

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

相关任务是这样的:

- 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

最佳答案

这就是我使用远程服务器上设置的 key 文件从 Github 进行部署的方式。如果 gitkeyfile 参数不起作用,那么您的剧本有问题:

- 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 - 如何在 ansible git 模块中使用远程机器的 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com