git - Vagrantfile 中的 Ansible – 从 git 中提取 playbook

标签 git vagrant ansible

我有 3 个 git 存储库:

  1. ansible 配置(角色、任务...)
  2. 后端代码
  3. 前端代码

在我的 Vagrantfile 中,我可以指定 playbook 的路径。

但是如果我想让 Ansible playbook 自动从 git 中 pull 怎么办? Vagrant 能做到吗?我不想有重复的 Ansible 配置。

或者我应该将我的 ansible 存储库添加为子模块?还是别的什么?

最佳答案

我也有好几个和你类似的情况。这就是我所做的...

所有三个存储库都位于同一父目录中。

./parent
  |-- ansible
  |-- backend
  +-- frontend

我使用vagrant-triggers当我执行 vagrant upvagrant provision 时触发对 ansible 存储库的更新的插件。所以我的 Vagrantfile 的开头可能看起来像

Vagrant.configure("2") do |config|
  config.trigger.before :up do
    system("../ansible/update.sh")
  end

其中../ansible/update.sh是一个脚本,用于检查以确保ansible git repo是最新的并且处于正确的状态(在正确的分支上等) .

下一部分是如果 ansible 存储库不存在,您是否希望后端和前端存储库能够自行引导。只需使用 vagrant-triggers 插件编写额外的 shell 脚本即可。另外,如果您愿意,可以使用 ansible 的 local_action (请参阅 docs )而不是 shell 脚本。

关于git - Vagrantfile 中的 Ansible – 从 git 中提取 playbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29918174/

相关文章:

git - 了解 Git : Latest push is not visible on production server

vagrant - Vagrant + VirtualBox VM sleep 后中止

ansible - 在 ansible 中以相反的顺序使用 concat 映射

networking - Vagrant 私有(private)网络

ansible - 在 Ansible 中如果没有 sudo 则无法 ping 主机

c# - 使用 Github 的 GraphQL 列出所有标签并搜索版本

git - 使用 Git 子模块来管理第 3 方依赖项?

Android Studio 无法启动 git,虽然实际上可以

linux - Vagrant中的Kafka集群(ZK、BR、BR、BR)无法建立连接

macos - 每次我的 OSX 机器启动时,如何自动执行 vagrant up?