file - 如何通过 Ansible 将 Git Repo 克隆到所有文件夹中
问题描述
我正在使用 Ansible 设置多个测试服务器环境(基本上是将相同的 Git 存储库复制到 test1-test55 不同的测试文件夹中)。
现在,我可以使用文件模块/包递归地创建这些文件夹,如下所示
- name: Creating multiple test environments
file: dest=/var/www/test{{ item }} state=directory
with_sequence: start=1 end=55
但我不确定如何使用 with_sequence 进行迭代,以便实际的 git clone 任务克隆 https://{{ githubuser | urlcode }}:{{ github密码 | urlencode }}@github.com/abc/sample.git 进入 test1,test2...test55 文件夹
我有这个任务将 git repo 克隆到单个文件夹/测试环境
- name: Clone repo to the newly created test environments
git:
repo: "https://{{ githubuser | urlencode }}:{{ githubpassword | urlencode }}@github.com/ABC/sample.git"
dest: /var/www/test1/sample #This will clone sample.git to test1, have tried using item here but gives an error
#with_sequence: start=1 end=55 #This does not work
应该对上述任务进行哪些更改,以便它可以在 playbook 的单次执行中递归地将相同的存储库克隆到所有 55 个文件夹
任何帮助,将不胜感激。
注意:组织和回购名称仅用于表示目的。
解决方案
您应该能够with_sequence
像使用它来创建目录一样使用它。
我设置了三个文件夹,名称分别test1
为 、和test2
,test3
并使用下面的任务将存储库克隆到所有文件夹中。这工作得很好。
- name: Clone repository into all folders
git:
repo: "<repo url>"
dest: "./test{{ item }}"
with_sequence: start=1 end=3
使之适应您的情况将导致类似于以下任务的结果。
- name: Clone repository into all folders
git:
repo: "https://{{ githubuser | urlencode }}:{{ githubpassword | urlencode }}@github.com/ABC/sample.git"
dest: "/var/www/test{{ item }}"
with_sequence: start=1 end=55
推荐阅读
- python - 弹出后的Robotframework android屏幕检测
- sql - 我如何将 postgres 查询转换为查询生成器格式 codeigniter?
- jmeter - HTTPS 响应的一部分在每个会话中都会发生变化
- c++ - 根据 hash_map 键类型更改宏以选择单独的定义
- javascript - 使用 javascript 在表格中添加新单元格
- azure - Azure 分析服务欧洲区域将哪些 IP 列入白名单?
- entity-framework-6 - 如果使用实体框架,子查询是否多次命中数据库
- php - 如果 else 语句不起作用,我应该如何解决
- android - Fabric 插件崩溃 --> 没有这样的属性:betaDistributionApkFilePath 类:org.codehaus.groovy.runtime.GStringImpl
- windows - 为什么 time.Now().UnixNano() 在 IO 操作后返回相同的结果?