具有可扩展性的多级部署 [英] Multistage deployment with ansible

查看:191
本文介绍了具有可扩展性的多级部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



主要思想是为不同阶段定义组变量。

主要思想是为不同阶段定义组变量。 / p>

有两个作品:





我想获得更多关于组织的例子

解决方案

最近,我使用了我已经提到的方法这个问题,这是我心中最方便的一个。



它取自可组合组Vars文件文章,但改变了一点,因为不幸的是,文章的标题并不反映它是真实的价值,目的和剧本名称也令人困惑。
其实呢,实际上要明白,实际上它是关于使用可复制的多级部署



你的应该是这样的:

  production / 
├──group_vars
│└──server.yml
└──库存
staging /
├──group_vars
│└──server.yml
└──库存
deploy.yml

使用非常简单: p>

  ansible-playbook -i staging deploy.yml 

其中 deploy.yml 是您的手册的名称。


当提供目录作为广告资源时,可以安装的搜索文件,默认搜索名为库存的文件所以没有必要指定 -i生产/库存,只有 -i生产将工作正常。


其优点是:




  • 您不需要像 [production:children]


  • 您不需要像 group_vars / production.yml


  • 所有的混淆组和文件变量和主机位于不同的目录中,因此很容易保持不同,变更历史也是明确的。如果您想要




,您甚至可以将它分割在不同的存储库中。您还可以使用 ansible-vault ,换句话说,存储所有重要变量加密


What approach would you advise to organize multistage deployment with ansible in case you have different variables for stages?

The main idea is defining group variables for different stages.

There are two artcles:

I'd like to get more examples about organizing playbooks, variables, hosts and understand advantages and disadvantages of your approach.

解决方案

Recently, I used the approach I had already mentioned in the question, and it occurred to be one of the most convenient to my mind.

It is taken from Organizing Group Vars Files in Ansible article, but altered a little, because, unfortunately, title of the article does not reflect it's real value and purpose and names of playbooks are confusing as well. In fact, it took a considerable time to understand that in fact it is about Multistage deployment with Ansible.

Your layout of directories should be like that:

production/
├── group_vars
│   └── server.yml
└── inventory
staging/
├── group_vars
│   └── server.yml
└── inventory
deploy.yml

And usage is extremely simple:

ansible-playbook -i staging deploy.yml

Where deploy.yml is the name of your playbook.

Ansible-playbook when provided a directory as the inventory, will search by default a file named inventory so no need to specify -i production/inventory, only -i production will work just fine.

And the benefits are:

  • You don't have to mantain some unnecessary groups like [production:children]

  • You don't need to keep confusing groups and files like like group_vars/production.yml

  • All vars and hosts are in separate directories, therefore it is easy to keep them different and history of changes is clear. You may even split it in separate repositories if you want

You may also keep secrets for production in repository using ansible-vault, in other words, store all your vital variables encrypted

这篇关于具有可扩展性的多级部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆