Recurring tasks

Hi !

I need a suggestion from you to solve a problem I’m facing, here it is…

The problem:
I have a ElasticSearch cluster composed of 6 nodes. During the non work hours I would like to substitute 4 of those 6 ec2 instance for a different server (cheaper instance). The main problem is: How can I proceed to the next server , and remove it from the cluster, since I must wait for the cluster to get in the “green state” ?

Below you can see how I stop the instances:

  • name: Stopping ES
    ec2:
    instance_ids: “{{ item }}”
    region: sa-east-1
    state: stopped
    wait: True
    with_items: es_ids
    tags:
  • esi_stop

and how I run the cluster health check:

  • name: Checking ES Cluster Status
    uri:
    url=http://<cluster_address>:9200/_cluster/health?pretty
    method=GET
    status_code=200
    register: cluster_status
    until: “‘{{ cluster_status.json.status }}’ == ‘green’”
    retries: 5
    delay: 30
    tags:
  • check_cluster_status

Thanks in advance!