문제

NGINX / Tomcat 인스턴스 쌍을 배포하는 데 사용할 수 있으며 배포 중에 가용성을 향상 시키려고합니다.

논리적 인스턴스는 1 nginx + 1 tomcat입니다. 2 개의 먼 위치가 2 개 이상 확산 된 4 개의 논리 인스턴스가 있습니다 (호스트 파일 벨로우즈 참조).

i deploy.xml이라는 플레이 북을 출시합니다.

- 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-Server 대신 onTigny-NGX 서버 (app-servers / ngx-server 대신)를 대상으로 할 수 있지만 두 번째 위치는 아니지만 PlayBook 컨텐츠를 복제해야합니다 (Add에 추가 해야하는 경우).다른 서버 위치).

제대로 만드는 모든 아이디어?

여기에 내 호스트 파일이 있습니다.

#
# 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
.

도움이 되었습니까?

해결책

One 솔루션은 Montigny-App-Server / Montigny-NGX-Server (App-Server / NGX 서버 대신)를 대상으로 한 다음 두 번째 위치

을 대상으로 할 수 있습니다.

이것은 우리가하는 일입니다. 커플 변경 :

기질 그룹 추가 :

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

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

다음에 -l /-limnit

옵션이있는 하위 집합에서 플레이 북을 실행할 수 있습니다.
$ ansible-playbooks -i inventory site.yml -l Montigny-servers && \
  ansible-playbooks -i inventory site.yml -l bievre-servers
.

이렇게하면 먼저 Montigny에서 논리적 인스턴스를 실행하고 모든 것이 잘 진행되면 (0을 종료하십시오), 바iveRe 인스턴스

에 대한 플레이 북을 실행합니다.

더 많은 exemples 찾기 : http://docs.ansible.com/playbooks_best_practices.html#what.- 조직 - 활성화 - 예제

다른 팁

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