elastic/ansible-elasticsearch

How can I disable multi-instance support

fedelemantuano opened this issue · 1 comments

Hi,

the problem is when you used old role version. If you leave the default, you will not see the old configuration and data.

Follow the origina thread:

Hello @fedelemantuano,

We didn't document it and test it but moving some folders is possible of course.

Something like this should work:

  • stop elasticsearch before
  • move es folders:
mv /etc/elasticsearch/{{ instance_name }}/* /etc/elasticsearch/ && rm -fr /etc/elasticsearch/{{ instance_name }}
mv /var/lib/elasticsearch/{{ node_name }}-{{ instance_name }}/* /var/lib/elasticsearch/ && rm -fr /var/lib/elasticsearch/{{ node_name }}-{{ instance_name }}
mv /var/log/elasticsearch/{{ node_name }}-{{ instance_name }}/* /var/log/elasticsearch/ && rm -fr /var/log/elasticsearch/{{ node_name }}-{{ instance_name }}
mv /var/run/elasticsearch/{{ node_name }}-{{ instance_name }}/* /var/run/elasticsearch/ && rm -fr /var/run/elasticsearch/{{ node_name }}-{{ instance_name }}
  • update ansible role to 7.1.1 release: ansible-galaxy install elastic.elasticsearch,7.1.1
  • check that es_conf_dir, es_data_dirs, es_log_dir, es_pid_dir and es_instance_name aren't overridded in your playbook (remove them if needed)
  • run your playbook
  • check that elasticsearch is started or start it if needed

⚠️ Of courses as this hasn't been tested, please backup your datas and conf before and validate the procedure in a test environment. After the migration, validate again that your data are still here.

If your prefer waiting more tests, feel free to create an issue in the repo to request testing and documenting this procedure and we'll do it when we'll have a little more time to dedicate to ansible-elasticsearch role.

Originally posted by @jmlrt in #554 (comment)

jmlrt commented

Hi @fedelemantuano,
I finally found time to validate the migration procedure for a single elasticsearch instance.

Test done with CentOS-7:

  • Install old version of Ansible role:
$ ansible-galaxy install elastic.elasticsearch,6.6.0
- downloading role 'elasticsearch', owned by elastic
- downloading role from https://github.com/elastic/ansible-elasticsearch/archive/6.6.0.tar.gz
- extracting elastic.elasticsearch to /home/jmlrt/.ansible/roles/elastic.elasticsearch
- elastic.elasticsearch (6.6.0) was installed successfully
  • Create minimal playbook:
$ cat << EOF >> playbook.yml
> - name: Simple Example
>   hosts: localhost
>   roles:
>     - role: elastic.elasticsearch
        es_instance_name: "node1"
        es_api_basic_auth_username: elastic
        es_api_basic_auth_password: changeme
> EOF
  • Deploy Ansible playbook:
$ ansible-playbook playbook.yml

...

PLAY RECAP 
localhost                  : ok=54   changed=22   unreachable=0    failed=0    skipped=122  rescued=0    ignored=0
  • Check ES health + insert datas:
$ curl localhost:9200/_cat/health?v
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1567163132 11:05:32  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%
$ curl -XPUT localhost:9200/customer/_doc/1 -d '{"name": "John Doe"}' -H'Content-Type: application/json'
{"_index":"customer","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
$ curl localhost:9200/customer/_doc/1
{"_index":"customer","_type":"_doc","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"name": "John Doe"}}
$ curl localhost:9200/_cat/health?v
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1567163149 11:05:49  elasticsearch yellow          1         1      5   5    0    0        5             0                  -                 50.0%
$ curl localhost:9200/_cat/indices?v
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   customer BreNAHWpQ_KGfMNiB5jvqg   5   1          1            0      4.2kb          4.2kb
  • Migrate data before new deployment without multi-instance support:
$ sudo -i
# systemctl stop elasticsearch
# mv /etc/elasticsearch/node1/* /etc/elasticsearch/ && rm -fr /etc/elasticsearch/node1/
mv: overwrite '/etc/elasticsearch/elasticsearch.keystore'? y
# mv /var/lib/elasticsearch/localhost-node1/* /var/lib/elasticsearch/ && rm -fr /var/lib/elasticsearch/localhost-node1/
# ls /var/lib/elasticsearch/
nodes
# mv /var/log/elasticsearch/localhost-node1/* /var/log/elasticsearch/ && rm -fr /var/log/elasticsearch/localhost-node1/
# rm -fr /var/log/elasticsearch/localhost-node1/
  • Update Ansible role version:
$ ansible-galaxy install --force elastic.elasticsearch,7.1.1
- changing role elastic.elasticsearch from 6.6.0 to 7.1.1
- downloading role 'elasticsearch', owned by elastic
- downloading role from https://github.com/elastic/ansible-elasticsearch/archive/7.1.1.tar.gz
- extracting elastic.elasticsearch to /home/jmlrt/.ansible/roles/elastic.elasticsearch
- elastic.elasticsearch (7.1.1) was installed successfully
  • Update playbook (remove es_conf_dir, es_data_dirs, es_log_dir, es_pid_dir and es_instance_name variables):
$ sed -i '/es_instance_name: "node1"/d' playbook.yml
$ cat playbook.yml
- name: Simple Example
  hosts: localhost
  roles:
    - role: elastic.elasticsearch
      es_api_basic_auth_username: elastic
      es_api_basic_auth_password: changeme
  • Deploy Ansible playbook again with new version of Ansible role:
$ ansible-playbook playbook.yml

...

TASK [elastic.elasticsearch : Create Directories] 
ok: [localhost] => (item=/var/run/elasticsearch)
ok: [localhost] => (item=/var/log/elasticsearch)
changed: [localhost] => (item=/etc/elasticsearch)
ok: [localhost] => (item=/var/lib/elasticsearch)

TASK [elastic.elasticsearch : Copy Configuration File]
changed: [localhost]

TASK [elastic.elasticsearch : Copy Default File]
changed: [localhost]

TASK [elastic.elasticsearch : Copy jvm.options File]
changed: [localhost]

...

RUNNING HANDLER [elastic.elasticsearch : restart elasticsearch] 
changed: [localhost]

...

PLAY RECAP
localhost                  : ok=26   changed=6    unreachable=0    failed=0    skipped=116  rescued=0    ignored=0
  • Check ES health + datas:
$ curl localhost:9200/_cat/health?v
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1567163898 11:18:18  elasticsearch yellow          1         1      5   5    0    0        5             0                  -                 50.0%
$ curl localhost:9200/customer/_doc/1
{"_index":"customer","_type":"_doc","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"name": "John Doe"}}
$ curl localhost:9200/_cat/indices?v
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   customer BreNAHWpQ_KGfMNiB5jvqg   5   1          1            0      4.3kb          4.3kb

Elasticsearch run successfully after the migration and the data we inserted before is still available.