具有可扩展性的多级部署 [英] Multistage deployment with ansible
问题描述
主要思想是为不同阶段定义组变量。
主要思想是为不同阶段定义组变量。 / p>
有两个作品:
我想获得更多关于组织的例子
最近,我使用了我已经提到的方法这个问题,这是我心中最方便的一个。
它取自组织可变文件中的组Vars文件文章,但改变了一点,因为不幸的是,文章没有反映出它的真正价值和目的,而且剧本的名称也令人困惑。
事实上,它花了相当多的时间才意识到这是关于使用可复制的多级部署。
您的布局
production /
├──group_vars
│ └──server.yml
└──库存
分期/
├──group_vars
│└──server.yml
└──库存
deploy.yml
使用非常简单:
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:
- http://rosstuck.com/multistage-environments-with-ansible/)
- (http://toja.io/using-host-and-group-vars-files-in-ansible/)
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 realize that 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屋!