使用ansible 安装es的tar包 到指定目录下 请给出代码示例
时间: 2024-05-11 15:15:05 浏览: 102
以下是使用Ansible安装ES tar包到指定目录的代码示例:
```
- name: Install Elasticsearch
hosts: elasticsearch_servers
vars:
es_version: "7.15.1"
es_download_url: "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{ es_version }}-linux-x86_64.tar.gz"
es_download_dir: "/tmp"
es_dir_name: "elasticsearch-{{ es_version }}"
es_install_dir: "/opt/elasticsearch"
tasks:
- name: Download Elasticsearch package
get_url:
url: "{{ es_download_url }}"
dest: "{{ es_download_dir }}/{{ es_dir_name }}.tar.gz"
- name: Unpack Elasticsearch package
unarchive:
src: "{{ es_download_dir }}/{{ es_dir_name }}.tar.gz"
dest: "{{ es_download_dir }}"
extra_opts: "--owner elasticsearch --group elasticsearch"
become: yes
- name: Move Elasticsearch directory to installation directory
file:
src: "{{ es_download_dir }}/{{ es_dir_name }}"
dest: "{{ es_install_dir }}"
state: link
become: yes
```
该示例使用变量指定ES的版本、下载链接、下载目录、安装目录等,通过`get_url`模块下载tar包,然后使用`unarchive`模块解压并设置文件夹所有者,最后使用`file`模块创建符号链接到指定目录下。
阅读全文