|
352 | 352 | name: elasticsearch
|
353 | 353 | state: started
|
354 | 354 | enabled: yes
|
| 355 | + register: elasticsearch_freshstart_security |
355 | 356 |
|
356 | 357 | - name: Wait for all instances to start
|
357 | 358 | ansible.builtin.include_tasks: wait_for_instance.yml
|
358 | 359 | loop: "{{ groups['elasticsearch'] }}"
|
359 | 360 |
|
360 |
| -- name: Force all notified handlers to run at this point, not waiting for normal sync points |
361 |
| - ansible.builtin.meta: flush_handlers |
362 |
| - tags: |
363 |
| - - certificates |
364 |
| - - renew_ca |
365 |
| - - renew_es_cert |
366 |
| - |
367 |
| -- name: Wait for all instances to start |
368 |
| - ansible.builtin.include_tasks: wait_for_instance.yml |
369 |
| - loop: "{{ groups['elasticsearch'] }}" |
370 |
| - tags: |
371 |
| - - certificates |
372 |
| - - renew_ca |
373 |
| - - renew_es_cert |
| 361 | +- name: Restart if Elasticsearch was already running |
| 362 | + when: |
| 363 | + - not elasticsearch_freshstart.changed | bool |
| 364 | + - not elasticsearch_freshstart_security.changed | bool |
| 365 | + block: |
| 366 | + - name: Force all notified handlers to run at this point, not waiting for normal sync points |
| 367 | + ansible.builtin.meta: flush_handlers |
| 368 | + tags: |
| 369 | + - certificates |
| 370 | + - renew_ca |
| 371 | + - renew_es_cert |
| 372 | + |
| 373 | + - name: Wait for all instances to start |
| 374 | + ansible.builtin.include_tasks: wait_for_instance.yml |
| 375 | + loop: "{{ groups['elasticsearch'] }}" |
| 376 | + tags: |
| 377 | + - certificates |
| 378 | + - renew_ca |
| 379 | + - renew_es_cert |
374 | 380 |
|
375 | 381 | - name: Check for passwords being set
|
376 | 382 | ansible.builtin.stat:
|
|
383 | 389 | elasticsearch_http_protocol: "https"
|
384 | 390 | when: elasticsearch_http_security
|
385 | 391 |
|
| 392 | +- name: Check for API with bootstrap password |
| 393 | + ansible.builtin.uri: |
| 394 | + url: "{{ elasticsearch_http_protocol }}://localhost:{{ elasticstack_elasticsearch_http_port }}" |
| 395 | + user: elastic |
| 396 | + password: "{{ elasticsearch_bootstrap_pw }}" |
| 397 | + validate_certs: false |
| 398 | + register: elasticsearch_api_status_bootstrap |
| 399 | + changed_when: false |
| 400 | + no_log: "{{ elasticstack_no_log }}" |
| 401 | + when: |
| 402 | + - not elasticsearch_passwords_file.stat.exists | bool |
| 403 | + - groups['elasticsearch'] | length > 1 |
| 404 | + until: elasticsearch_api_status_bootstrap.json.cluster_name is defined |
| 405 | + retries: 5 |
| 406 | + delay: 10 |
| 407 | + |
| 408 | +# We need this check twice. One to wait for the API to be actually available. And a second time to |
| 409 | +# check the actual return code. Should not cause a huge delay. |
| 410 | + |
386 | 411 | - name: Check for cluster status with bootstrap password
|
387 | 412 | ansible.builtin.uri:
|
388 | 413 | url: "{{ elasticsearch_http_protocol }}://localhost:{{ elasticstack_elasticsearch_http_port }}/_cluster/health?pretty"
|
|
410 | 435 | delegate_to: "{{ elasticstack_ca }}"
|
411 | 436 | when: elasticsearch_passwords_file.stat.exists | bool
|
412 | 437 |
|
| 438 | +- name: Check for API availability with elastic password |
| 439 | + ansible.builtin.uri: |
| 440 | + url: "{{ elasticsearch_http_protocol }}://localhost:{{ elasticstack_elasticsearch_http_port }}" |
| 441 | + user: elastic |
| 442 | + password: "{{ elasticstack_password.stdout }}" |
| 443 | + validate_certs: false |
| 444 | + register: elasticsearch_api_status |
| 445 | + changed_when: false |
| 446 | + no_log: "{{ elasticstack_no_log }}" |
| 447 | + when: |
| 448 | + - elasticsearch_passwords_file.stat.exists | bool |
| 449 | + - groups['elasticsearch'] | length > 1 |
| 450 | + until: elasticsearch_api_status.json.cluster_name is defined |
| 451 | + retries: 20 |
| 452 | + delay: 10 |
| 453 | + |
| 454 | +- name: Work around low ressources on CI/CD nodes |
| 455 | + when: ansible_virtualization_type == "container" or ansible_virtualization_type == "docker" |
| 456 | + block: |
| 457 | + # Free up some space to let elsticsearch allocate replica in GitHub Action |
| 458 | + - name: Remove cache |
| 459 | + ansible.builtin.command: > |
| 460 | + rm -rf /var/cache/* |
| 461 | + changed_when: false |
| 462 | + |
| 463 | + - name: Set persistent watermarks to very high values in Docker # noqa: risky-shell-pipe |
| 464 | + ansible.builtin.shell: > |
| 465 | + if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
| 466 | + curl |
| 467 | + -k |
| 468 | + -X PUT |
| 469 | + "{{ elasticsearch_http_protocol }}://elastic:{{ elasticstack_password.stdout }}@localhost:9200/_cluster/settings" |
| 470 | + -H 'Content-Type: application/json' -d |
| 471 | + ' |
| 472 | + { |
| 473 | + "persistent": { |
| 474 | + "cluster.routing.allocation.disk.watermark.low": "97%", |
| 475 | + "cluster.routing.allocation.disk.watermark.high": "98%", |
| 476 | + "cluster.routing.allocation.disk.watermark.flood_stage": "99%", |
| 477 | + "cluster.routing.allocation.disk.watermark.flood_stage.frozen": "99%" |
| 478 | + } |
| 479 | + } |
| 480 | + ' |
| 481 | + changed_when: false |
| 482 | + no_log: "{{ elasticstack_no_log }}" |
| 483 | + when: |
| 484 | + - elasticstack_password.stdout is defined |
| 485 | + |
| 486 | +# We need this check twice. One to wait for the API to be actually available. And a second time to |
| 487 | +# check the actual return code. Should not cause a huge delay. |
| 488 | + |
413 | 489 | - name: Check for cluster status with elastic password
|
414 | 490 | ansible.builtin.uri:
|
415 | 491 | url: "{{ elasticsearch_http_protocol }}://localhost:{{ elasticstack_elasticsearch_http_port }}/_cluster/health?pretty"
|
|
0 commit comments