質問

NGINX / Tomcatインスタンスのペアを展開するためのAnsibleを使用しています。展開中に可用性を向上させようとしています。

論理インスタンスは1 nginx + 1 tomcatです.4つの論理インスタンスが2つ以上の場所に広がる(ホストファイルのベローを参照)。

私はこのような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
.

私が欲しいのは、他の論理インスタンスの50%を展開する前に、他の論理インスタンスの50%を展開することです(そして何か問題が発生した場合はすべてを停止します)。 1つのソリューションは、最初にmontigny-app-server / montigny-ngx-serverをターゲットにしている可能性があります(app-server / ngx-serversの代わりに)、次に2番目の場所ですが、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
.

役に立ちましたか?

解決

1つのソリューションは、まずMontigny-app-server / montigny-ngx-serverをターゲットにしている可能性があります(App-Server / NGX-Serverの代わりに)、次に2番目の場所

これは私たちがすること、カップルの変更点:

ジオロケーショングループを追加する:

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

[bievre-servers:children]
bievre-app-servers
bievre-ngx-servers
.

その後、オプションを使用してサブセットのプレイブックを実行できます。/ - limnit

$ ansible-playbooks -i inventory site.yml -l Montigny-servers && \
  ansible-playbooks -i inventory site.yml -l bievre-servers
.

このようにして、まずMontignyから論理インスタンスを実行します。そして、すべてがうまくいったら(0番出口)、Bievreインスタンスのプレイブックを実行します。

もっとexemplesを見つける: http://docs.ansible.com/playbooks_best_practices.html# - 整理 - イネーブル - 例

他のヒント

I agree with the idea of putting your hosts in separate groups so that you can run commands on first one group and then the other.

You should be able to put that in one playbook though - if you create the fundamental actions in an include script, you can then create a playbook that will have multiple '- hosts' sections, each of which will call the include script.

That would look something like:

---
- hosts: firstgroupname
  tasks:
    - include: pathandnameofincludescript.yaml
- hosts: secondgroupname
  tasks:
    - include: pathandnameofincludescript.yaml

and your include script would look something like:

---
- name: action 1
  command: echo hello world
- name: action 2
  command: echo hello again

Note the indentation difference for include scripts - its very important! YAML can be annoying at times....

Okay, here is what I think you actually want.

You can use the serial keyword to say how many hosts ansible should manage at a single time in a play. So in the example below, ansible would only run the plays on two hosts at a time.

By default, anisble will keep running the plays even if the first two machines fail, so you can use the max_fail_percentage keyword to define the percentage of failures acceptable before stopping. In the example below, Ansible will stop if 1 percent of machines failed.

Source: http://docs.ansible.com/playbooks_delegation.html#rolling-update-batch-size

- hosts: app-servers`
  serial: 2 
  max_fail_percentage: 1
  roles: 
   - role: deploy-env

And then in your deploy-env role have:

- 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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top