---
  # https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
  - name: set vm.max_map_count
    command: sysctl -w vm.max_map_count=262144

  - name: start elasticsearch container
    docker_container:
      name: elasticsearch
      image: "docker.elastic.co/elasticsearch/elasticsearch:{{ es_version }}"
      restart_policy: always
      network_mode: host
      env:
        bootstrap.memory_lock: "true"
        ES_JAVA_OPTS: "-Xms512m -Xmx512m"
      ulimits:
        - memlock:-1:-1
      volumes:
        - /usr/share/elasticsearch/data

  - name: POST templates to elasticsearch
    uri:
      url: "http://localhost:9200/_template/template_{{ item.template_num }}"
      body: "{{ lookup('url', locations_api_raw_url+locations_api_branch+'/'+item.filename, split_lines=False) }}"
      method: POST
      body_format: json
    with_items:
      - { filename: "{{ locations_template_filename }}", template_num: "1" }
      - { filename: "{{ services_template_filename }}", template_num: "2" }

---
  # https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
  - name: set vm.max_map_count
    sysctl:
      name: vm.max_map_count
      value: 262144

  - name: start elasticsearch container
    docker_container:
      name: elasticsearch
      image: "docker.elastic.co/elasticsearch/elasticsearch:{{ es_version }}"
      restart_policy: always
      network_mode: host
      env:
        bootstrap.memory_lock: "true"
        ES_JAVA_OPTS: "-Xms512m -Xmx512m"
      ulimits:
        - memlock:-1:-1
      volumes:
        - /usr/share/elasticsearch/data

  - name: POST templates to elasticsearch
    uri:
      url: "http://localhost:9200/_template/template_{{ item.template_num }}"
      body: "{{ lookup('url', locations_api_raw_url+locations_api_branch+'/'+item.filename, split_lines=False) }}"
      method: POST
      body_format: json
    with_items:
      - { filename: "{{ locations_template_filename }}", template_num: "1" }
      - { filename: "{{ services_template_filename }}", template_num: "2" }

Use sysctl Ansible module instead of command in elasticsearch
Use sysctl Ansible module instead of command in elasticsearch
