运行 来自 git 回购的剧本在剧本执行期间被克隆

Run playbook from git repo cloned during playbook execution

我似乎无法从 ansible 文档中弄清楚这一点。

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

假设我有一个 git 回购 A,它有一个 ansible playbook X。我还有一个 git repo B,它有一个 ansible playbook Y。我想要的是在执行期间X,克隆 B,然后 运行 playbook Y。这似乎是那种应该很容易 google 的事情,事实上它并不让我想知道我是否要去这都错了。

这是我在剧本 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 设置为是,它仍然告诉我它无法在 Ansible Controller 上找到 /tmp/B/Y.yml,所以它似乎在我的本地机器上而不是远程机器上寻找. Repo B 已正确克隆到远程的 /tmp(通过 ssh 确认)。

这可以通过 gitfetchinclude_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 必须是简单的任务列表。因为我也希望能够 运行 它既独立又包含在 repo 的项目中 A 我在它的 repo 中放了一个剧本,它只包含并 运行s 它。

另外参考我的第一种方法的误导性错误消息(参见问题的评论),看起来他们已经 already patched it