cognifloyd.bitbucket-sources

Ansible角色:Bitbucket源

构建状态

此角色使用访问密钥克隆/拉取Bitbucket云仓库。克隆仓库可以位于指定用户拥有的任何位置。如果用户或位置不存在,将会被创建。

使用include_role/import_role时,此角色可以多次使用。其他方法未经测试。

在CI中测试的场景:

  • 通过匿名HTTPS访问的公共git仓库
  • 通过SSH使用密钥访问的公共git仓库
  • 通过SSH使用密钥访问的私有git仓库
  • 通过匿名HTTPS访问的公共hg仓库

待办事项:hg私有仓库支持需要设置SSH密钥的方式。 待办事项:hg公共仓库通过SSH支持需要测试(密钥必须在SSH配置中)。

注意:此角色从cognifloyd/ansible-role-bitbucket_sources移出。

要求

此角色假设已安装源代码控制可执行程序(git或hg)。如果需要指定非标准可执行文件位置,请设置可选变量bitbucket_sources_executable

角色变量

构造克隆URL

此角色使用以下三个变量(我称之为<type><account><name>)生成Bitbucket云仓库的URL:

  • bitbucket_sources_repo_type (有效选项:"git"、"hg")
  • bitbucket_sources_repo_account
  • bitbucket_sources_repo_name

根据<type>是git还是hg,URL将会是(详见bitbucket文档):

可以将bitbucket_sources_altssh布尔值设置为"yes"以使用altssh URL

如果不想使用SSH,可以将bitbucket_sources_protocol设置为https(默认是ssh)。 此角色仅支持匿名HTTPS。使用HTTPS时,URL为:

  • https://bitbucket.org/<account>/<name>.git
  • https://bitbucket.org/<account>/<name>

克隆目标

仓库将克隆为bitbucket_sources_dest,由bitbucket_sources_owner:bitbucket_sources_group拥有(便于引用为<dest><owner><group>)。<dest>的父目录必须是由<owner>:<group>拥有的目录,如果不存在,将被创建。该目录将具有在bitbucket_sources_mode中定义的权限模式。

克隆将由bitbucket_sources_owner创建,并归属于bitbucket_sources_group,并将具有该用户/组的权限。

Bitbucket要求某种凭据以访问仓库,因此您需要在bitbucket_sources_key中提供Bitbucket访问密钥。如果密钥不应从控制器复制到ansible_host(例如,密钥在目标ansible_host上生成,或者您在其他角色/剧本中部署了密钥等),则将bitbucket_sources_key_copy设置为falseno

** 待办事项:** 在此角色中添加推送公共密钥到Bitbucket的选项。根据bitbucket_sources_key_copy的值,从ansible_host(当true时)或ansible_controller(当false时)抓取密钥。这可能需要一个额外的变量用于后缀,但可能只是{{ bitbucket_sources_key }}.pub。相关API是部署密钥(用于一或多个仓库的只读访问)和SSH密钥(用于特定用户的完全访问)。将需要某种登录凭证。

** defaults/main.yml **:

bitbucket_sources_repo_type: git
bitbucket_sources_owner: "{{ ansible_user }}"
bitbucket_sources_group: "{{ ansible_user }}"
bitbucket_sources_mode: 0755
bitbucket_sources_altssh: no
bitbucket_sources_key_dest: "~{{ bitbucket_sources_owner }}/.ssh/{{ bitbucket_sources_key | basename }}"
bitbucket_sources_key_copy: yes
bitbucket_sources_force: no

** vars/main.yml **:

none

** 角色参数 **:

您必须将这些设置为角色参数(没有默认值,如果未定义,则断言将失败):

bitbucket_sources_repo_account: "<bitbucket用户>"
bitbucket_sources_repo_name: "<bitbucket仓库(不带.git)>"
bitbucket_sources_dest: "~<用户>/scm/<account>/<name>.git"
bitbucket_sources_key: "~/.ssh/access_key"

您也可以覆盖任何默认值(见上文)。其他可选变量包括:

bitbucket_sources_version: a83b8a42
bitbucket_sources_executable: "/home/acme/gentoo-prefix/usr/bin/git"
bitbucket_sources_force: yes

** 待办事项:** 我不知道如何让hg使用指定的密钥。

** 全局作用域变量 **: 从全局作用域(即hostvars,group vars等)读取的任何变量。

默认情况下,<owner><group>设置为ansible_user

ansible_user

** 来自其他角色的变量 **: 从其他角色读取的任何变量。

none

依赖关系

没有外部依赖关系。

示例剧本

- hosts: vagrant
  tasks:
    - name: 从Bitbucket克隆或强制更新example-magnificent。
      include_role:
        name: theatro.bitbucket_sources
        allow_duplicates: yes
        public: no
      vars:
        bitbucket_sources_repo_type: git
        bitbucket_sources_repo_account: example
        bitbucket_sources_repo_name: magnificent
        bitbucket_sources_dest: /var/scm/bitbucket/example/magnificent.git
        bitbucket_sources_owner: vagrant
        bitbucket_sources_group: vagrant
        bitbucket_sources_key: "~/.ssh/example_access_key"
        bitbucket_sources_force: yes

许可证

MIT

作者信息

Jacob Floyd创作,受雇于Theatro,于2017年。我从另一篇剧本中提取了这些任务。在编写大部分内容后,我发现了webbylab.sourcesStouts.source。名称“sources”比我工作中的“bitbucket-repo-clone”好多了,所以我改用“bitbucket-sources”。遗憾的是,我使用的是EL 7,因此这些以Ubuntu为中心的角色即使在我写大部分内容之前找到,可也需要适配。尽管我没有重用太多想法,但他们值得被记住。

关于项目

Clone/update a bitbucket cloud repository

安装
ansible-galaxy install cognifloyd.bitbucket-sources
许可证
Unknown
下载
105
拥有者