Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ansible的高可用性部署_Ansible - Fatal编程技术网

使用Ansible的高可用性部署

使用Ansible的高可用性部署,ansible,Ansible,我正在使用Ansible部署成对的NGinx/Tomcat实例,并试图在部署期间提高可用性 一个逻辑实例是1个NGinx+1个Tomcat:我有4个逻辑实例分布在2个遥远的位置(参见下面的hosts文件) 我启动了一个名为deploy.xml的playbook,如下所示: - hosts: ngx-servers pre_tasks: - include: tasks/remove-server.yml roles: - role: ngx-server - hosts

我正在使用Ansible部署成对的NGinx/Tomcat实例,并试图在部署期间提高可用性

一个逻辑实例是1个NGinx+1个Tomcat:我有4个逻辑实例分布在2个遥远的位置(参见下面的hosts文件)

我启动了一个名为deploy.xml的playbook,如下所示:

- hosts: ngx-servers
  pre_tasks:
    - include: tasks/remove-server.yml
  roles:
    - role: ngx-server

- hosts: app-servers
  roles:
    - role: app-server

- hosts: ngx-servers
  tasks:
    - include: tasks/add-server.yml
我想要的是在部署其他逻辑实例之前,先部署4个逻辑实例中的50%(如果出现问题,则停止所有操作)。 一种解决方案可能是首先针对montigny app server/montigny ngx服务器(而不是app server/ngx服务器),然后是第二个位置,但我需要复制playbook内容(如果我需要添加其他服务器位置,则依此类推)

有没有什么好办法

这是我的主机文件:

#
# Serveurs d'application
#

# Montigny
[montigny-app-servers]
mo-app-server-1 ansible_ssh_host=1y.domain.fr ansible_ssh_user=devops
mo-app-server-2 ansible_ssh_host=2y.domain.fr ansible_ssh_user=devops

# Bievre
[bievre-app-servers]
bi-app-server-1 ansible_ssh_host=1b.domain.fr ansible_ssh_user=devops
bi-app-server-2 ansible_ssh_host=2b.domain.fr ansible_ssh_user=devops

# Tous
[app-servers:children]
montigny-app-servers
bievre-app-servers

#
# Serveurs NGinx
#

# Montigny
[montigny-ngx-servers]
mo-ngx-server-1 ansible_ssh_host=1y.domain.fr ansible_ssh_user=devops
mo-ngx-server-2 ansible_ssh_host=2y.domain.fr ansible_ssh_user=devops

# Bievre
[bievre-ngx-servers]
bi-ngx-server-1 ansible_ssh_host=1b.domain.fr ansible_ssh_user=devops
bi-ngx-server-2 ansible_ssh_host=2b.domain.fr ansible_ssh_user=devops

# Tous
[ngx-servers:children]
montigny-ngx-servers
bievre-ngx-servers

好吧,这是我认为你真正想要的

您可以使用serial关键字来说明ansible在一个剧本中一次应管理多少台主机。因此,在下面的示例中,ansible一次只能在两台主机上运行播放

默认情况下,即使前两台机器出现故障,anisble仍将继续运行播放,因此您可以使用max\u fail\u percentage关键字定义停止前可接受的故障百分比。在下面的示例中,如果1%的机器出现故障,Ansible将停止

来源:

然后在您的部署环境角色中:

- name: remove from LB
  include: remove-server.yml
  delegate_to: paired_nginx_box

  /* app-server tasks */

- name: add to LB
  include: add-server.yml
  delegate_to: paired_nginx_box
一种解决方案可能是先将montigny应用程序服务器/montigny ngx服务器作为目标(而不是应用程序服务器/ngx服务器),然后再将第二个位置作为目标

这就是我们所做的,几个变化:

添加地理定位组:

[Montigny-servers:children]
montigny-app-servers
montigny-ngx-servers

[bievre-servers:children]
bievre-app-servers
bievre-ngx-servers
然后,您可以使用选项-l/--limnit在子集上执行playbook

这样,它将首先从Montigny运行逻辑实例,如果一切正常(退出0),它将运行bievre实例的playbook

查找更多示例:
我同意将主机分为不同的组,这样您就可以在第一个组和另一个组上运行命令

不过,您应该能够将其放在一个剧本中——如果您在包含脚本中创建基本动作,那么您可以创建一个剧本,其中包含多个“-hosts”部分,每个部分都将调用包含脚本

这看起来像:

---
- hosts: firstgroupname
  tasks:
    - include: pathandnameofincludescript.yaml
- hosts: secondgroupname
  tasks:
    - include: pathandnameofincludescript.yaml
---
- name: action 1
  command: echo hello world
- name: action 2
  command: echo hello again
您的include脚本将类似于:

---
- hosts: firstgroupname
  tasks:
    - include: pathandnameofincludescript.yaml
- hosts: secondgroupname
  tasks:
    - include: pathandnameofincludescript.yaml
---
- name: action 1
  command: echo hello world
- name: action 2
  command: echo hello again

注意include脚本的缩进差异——这非常重要!YAML有时会令人讨厌……

我已经完成了Ansible剧本片段。对于您介绍的解决方案,它将不起作用,因为playbook将首先在每个NGinx服务器上执行remove-server.yml任务,然后再执行下一步。我认为该解决方案仍然可以工作,但我需要一点澄清。remove-server.yml和add-server.yml剧本做什么?你是在拆掉你的nginx盒子然后再建造新的吗?是的,你是对的,remove-server.yml从前端负载平衡器中移除nginx服务器,和add-server.yml使其可从LB获得。删除所有NGinx服务器意味着在安装过程中随时杀死我需要至少一个实例的所有应用程序实例。你如何知道哪些NGinx服务器与哪些应用程序服务器相比?好问题:)事实上,因为我在每个位置工作,我不需要知道这些信息,因为我禁用了一个位置的所有NGinx,然后更新了同一位置上的应用程序。嗯,很有趣,但也有一些问题:包含的脚本需要针对不同种类的服务器(NGinx或app),当针对主机组时,我不能在另一个playbook中包含playbook(montigny服务器和bievre服务器)在第一个剧本中(考虑您的示例,需要在所包含的脚本中以主机为目标)然后做4个任务组:1:biervre应用程序,include app.yml 2:bievre nginx,include nginx.yml 3:mont应用程序,include app.yml 4:mont nginx,include nginx.yml这样做代码重复最少这是一个解决方案,但不是KISS(保持简单和愚蠢)因为它需要很多文件。我更喜欢ant31的解决方案。谢谢你花时间回答我。你是对的,只是它需要调用ansible playbooks两次,这不是很好:这是ansible在其最佳实践中描述的方式(见链接)。否则,将“keba”作为您在一个Playbook中运行它的解决方案好吧,您可以用您的解决方案说服我,这是最简单的解决方案。谢谢您的帮助:)