简体   繁体   English

通过Ansible剧本部署应用程序而不会降低双方

[英]Deploying application via Ansible playbook without bringing both sides down

I'm using Ansible to deploy a Java web application. 我正在使用Ansible部署Java Web应用程序。 Deployment is quiet basic via Ansible running a Jenkins playbook, copying a jar-file to 2 separate application servers, called node-01a and node-01b, both behind an Amazon AWS load balancer. 通过Ansible运行Jenkins剧本,将jar文件复制到2个单独的应用程序服务器(分别称为node-01a和node-01b),两者均位于Amazon AWS负载均衡器后面,从而实现了安静的部署。

Currently the deployment happens on both the node-01a and node-01b at the same time. 当前,部署同时在node-01a和node-01b上进行。 What would be the easiest way to do this without both nodes going down at the same time? 没有两个节点同时关闭的最简单方法是什么?

You can use serial parameter for the task. 您可以为任务使用serial参数。 See documentation . 请参阅文档 This is per play. 这是每场比赛。

You can also specify 'degree of parallelism' at playbook level with command line param --forks=FORKS . 您还可以使用命令行参数--forks=FORKS在剧本级别指定“并行度”。

Probably not relevant for you but just for completeness let me also quote that : 可能与您无关,而只是为了完整性,我还引用以下内容

Tasks are executed in order, one at a time, against all machines matched by the host pattern, before moving on to the next task. 在继续执行下一个任务之前,针对与主机模式匹配的所有机器,一次执行一个任务。

I prefer to run rolling updates in a region by region basis using tags inside an Ansible playbook. 我更喜欢使用Ansible剧本中的标签在每个区域中进行滚动更新。 You should always have your ELB servers in multiple zones, so using that principal is a good idea. 您应该始终将ELB服务器放在多个区域中,因此使用该主体是一个好主意。

For any one server, lets suppose you have two tags - Application (Application:SuperApp as an example) and AvailabilityZone (AvailabilityZone:us-east-1a, AvailabilityZone:us-east-1d as examples). 对于任何一台服务器,假设您有两个标记-应用程序(例如Application:SuperApp)和AvailabilityZone(例如AvailabilityZone:us-east-1a,AvailabilityZone:us-east-1d)。 I do this to ensure I'm only running my script when both Application is set to SuperApp as well as AvailabilityZone is set to the appropriate zone when the script is run. 我这样做是为了确保仅在运行脚本时将两个Application都设置为SuperApp并将AvailabilityZone都设置为适当的区域时才运行脚本。

This then allows me to use an include script called 'doCoolStuff.yaml' like so when using the ec2.py inventory script: 然后,这使我可以使用名为'doCoolStuff.yaml'的包含脚本,就像在使用ec2.py库存脚本时那样:

- hosts: tag_Application_SuperApp:&tag_AvailabilityZone_us-east-1a
  gather_facts: False
  roles:
    - doCoolStuffRole
  tasks:
    - include: doCoolStuff.yaml

- hosts: tag_Application_SuperApp:&tag_AvailabilityZone_us-east-1d
  gather_facts: False
  roles:
    - doCoolStuffRole
  tasks:
    - include: doCoolStuff.yaml

Of course you need to do much more inside your doCoolStuffRole Role and your doCoolStuff.yaml include script, but the overall process is included in the above. 当然,您需要在doCoolStuffRole角色和doCoolStuff.yaml包含脚本中做更多的工作,但是上面包括了整个过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM