从执行剧本期间克隆的git repo运行剧本

时间:2018-09-14 14:52:54

标签: ansible vagrant

我似乎无法从Ansible文档中找出答案。

我有一个剧本X,我想在各种情况下重用。像任何优秀的软件工程师一样,我将其放在源代码控制(git)的存储库中。所以我希望我的其他剧本能够被抓住并包括在内,我该如何实现呢?我可以将回购包含X作为子树,但这并不理想。

比方说,我有一个git repo A,其中有一个可播放的剧本X。我也有一个git repo B,其中有一个可播放的剧本Y。我要执行的是X的执行过程中,克隆B然后运行剧本Y 。。。。。。。。。。。。。。。。。。。。。。。。。。。pp。。。。。。。。。。。

这是我在剧本X中尝试过的内容:

- name: Clone B
      git:
        repo: 'http://{{ git_user }}:{{ git_pass }}@somehost/B.git'
        dest: /tmp/B

- name: Run Y
      include_tasks: /tmp/B/Y.yml
      remote_src: yes

即使我将remote_src设置为yes,它仍然告诉我在Ansible Controller上找不到/tmp/B/Y.yml,因此它似乎是在我的本地机器上而不是在遥控器上。存储库B已正确克隆到远程服务器上的/tmp(通过ssh确认)。

1 个答案:

答案 0 :(得分:0)

这可以通过结合fetchinclude_tasks- name: Clone B on the remote git: repo: 'http://{{ git_user }}:{{ git_pass }}@somehost/B.git' dest: /tmp/B # This copies the specified file from the remote to the current dir - name: Fetch yml from remote fetch: src: /tmp/B/Y.yml dest: ./ flat: yes - name: Run Y include_tasks: Y.yml 模块来实现:

Y.yml

请注意,A必须是简单的任务列表。由于我还希望既可以独立运行它,也可以将其包含在回购ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux] 中的项目中,所以我将一本剧本放到了仅包含并运行它的回购中。

在我的第一种方法中也提到了误导性错误消息(请参阅问题注释),看起来他们已经already patched it