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

问题描述 投票:0回答:1

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

我有一个我想在各种环境中重用的剧本X.像任何优秀的软件工程师一样,我把它放在源代码控制(git)的repo中。所以我希望我的其他剧本能够抓住并包含它,我该如何实现呢?我可以用X作为子树包含repo,但这并不理想。

假设我有一个git repo A有一个ansible playbook X.我也有一个git repo B有一个ansible playbook Y.我想要的是在执行X,克隆B然后运行playbook Y.这似乎就像那种应该很容易google的东西,以及它不会让我想知道我是否会这么做错。

这是我在playbook 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控制器上找到/tmp/B/Y.yml,所以它似乎在我的本地盒而不是遥控器上查找。 Repo B被正确克隆到遥控器上的/tmp(通过ssh确认)。

ansible vagrant
1个回答
0
投票

这可以通过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中添加了一个playbook,它包含并运行它。

另外参考我的第一种方法的误导性错误信息(参见问题的评论),它看起来像是already patched it

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.