加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Ansible Mercurial克隆挂起

发布时间:2020-12-20 11:27:14 所属栏目:Python 来源:网络整理
导读:当我尝试使用Ansible从Bitbucket克隆存储库时,似乎任务“挂起”. 在documentation我找到了一些信息,但我没有使用SSH. If the task seems to be hanging,first verify remote host is in known_hosts. SSH will prompt user to authorize the first contact w
当我尝试使用Ansible从Bitbucket克隆存储库时,似乎任务“挂起”.

在documentation我找到了一些信息,但我没有使用SSH.

If the task seems to be hanging,first verify remote host is in
known_hosts. SSH will prompt user to authorize the first contact with
a remote host. One solution is to add StrictHostKeyChecking no in
.ssh/config which will accept and authorize the connection on behalf
of the user. However,if you run as a different user such as setting
sudo to True),for example,root will not look at the user .ssh/config
setting.

这些是我试过的两本Playbooks.他们都“挂”.

Playbook#1

- hosts: staging_mysql
  user: ec2-user
  sudo: yes

  vars_files:
    - vars/mercurial.yml

  tasks:
    - name: Mercurial credentials setup
      action: template src=templates/hgrc.j2 dest=/home/ec2-user/.hgrc

    - name: Install Mercurial
      action: yum name=hg

    - name: Setup API repository
      action: command hg clone https://bbusername@bitbucket.org/username/my-repo -r default --debug

Playbook#2

- hosts: staging_mysql
  user: ec2-user
  sudo: yes

  vars_files:
    - vars/mercurial.yml

  tasks:
    - name: Mercurial credentials setup
      action: template src=templates/hgrc.j2 dest=/home/ec2-user/.hgrc

    - name: Install Mercurial
      action: yum name=hg

    - name: Clone API repo
      hg: dest=/home/ec2-user repo=https://bbusername@bitbucket.org/username/my-repo

欢迎任何帮助.提前致谢!

解决方法

我为那些想要克隆私有存储库的人找到了更好的答案. Bitbucket具有称为“部署密钥”的功能.登录您的项目,进入“设置”和“部署密钥”. “添加密钥”,然后在项目部署过程中,在hg之前提供此密钥:

- file: dest=/var/www/someuser/.ssh/config state=touch mode=600

- lineinfile: dest=/var/www/someuser/.ssh/config
              line="Host bitbucket.org"
              state=present

- copy: src=someuser.key dest=/var/www/someuser/.ssh/id_rsa mode=0600
- copy: src=someuser.key.pub dest=/var/www/someuser/.ssh/id_rsa.pub mode=0600


- lineinfile: dest=/var/www/someuser/.ssh/config
              line="IdentityFile ~/.ssh/id_rsa"

- lineinfile: dest=/var/www/someuser/.ssh/config
              line="    StrictHostKeyChecking no"
              insertafter="Host bitbucket.org"
              state=present

- name: install site code
  hg: repo='ssh://hg@bitbucket.org/somecode'
      dest=someuser
      revision=stable
  tags: someuser_code

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读