From edadec6ca61a41fdc1437cb63fa784028e38b0a3 Mon Sep 17 00:00:00 2001 From: Jonathan Strootman Date: Tue, 19 Jan 2016 13:33:56 -0700 Subject: [PATCH] Updating to install 2.x, support CentOS 7 install --- defaults/main.yml | 13 ++++---- meta/main.yml | 5 +++- tasks/custom-jars.yml | 5 ++-- tasks/elastic-install.yml | 62 ++++++++++++++++++++++++++++++--------- tasks/java.yml | 7 +++-- tasks/main.yml | 17 +++++++++++ tasks/plugins.yml | 2 +- tasks/spm.yml | 7 +++-- tests/test1_var.yml | 2 +- 9 files changed, 90 insertions(+), 30 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 95762a5..d829306 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,15 +3,16 @@ elasticsearch_user: elasticsearch elasticsearch_group: elasticsearch -elasticsearch_download_url: https://download.elasticsearch.org/elasticsearch/elasticsearch elasticsearch_version: 1.7.3 elasticsearch_apt_repos: - 'ppa:webupd8team/java' -elasticsearch_apt_java_package: oracle-java7-installer -elasticsearch_apt_dependencies: - - htop - - ntp - - unzip +elasticsearch_java_package: oracle-java7-installer +elasticsearch_pkg_dependencies: + - htop + - ntp + - unzip +elasticsearch_ubuntu_download_url: https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/{{elasticsearch_version}}/elasticsearch-{{elasticsearch_version}}.deb +elasticsearch_centos7_download_url: https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/{{elasticsearch_version}}/elasticsearch-{{elasticsearch_version}}.rpm elasticsearch_max_open_files: 65535 elasticsearch_home_dir: /usr/share/elasticsearch elasticsearch_plugin_dir: /usr/share/elasticsearch/plugins diff --git a/meta/main.yml b/meta/main.yml index 278abff..6ad5fb6 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,11 +4,14 @@ galaxy_info: author: "George Stathis" company: Traackr license: MIT - min_ansible_version: 1.3 + min_ansible_version: 1.9 platforms: - name: Ubuntu versions: - precise + - name: EL + versions: + - 7 categories: - database:nosql dependencies: [] diff --git a/tasks/custom-jars.yml b/tasks/custom-jars.yml index 097c4c0..67c8518 100644 --- a/tasks/custom-jars.yml +++ b/tasks/custom-jars.yml @@ -10,13 +10,14 @@ # - ... # Loop though elasticsearch_custom_jars and install them -- name: Installing Custom JARs +- name: custom jars | Installing Custom JARs action: > get_url url={{ item.uri }} url_username={{ item.user }} url_password={{ item.passwd }} dest="{{ elasticsearch_home_dir }}/lib/{{ item.filename }}" with_items: elasticsearch_custom_jars # Fix permissions -- file: > +- name: custom jars | + file: > path="{{ elasticsearch_home_dir }}/lib" state=directory owner={{ elasticsearch_user }} group={{ elasticsearch_group }} recurse=yes diff --git a/tasks/elastic-install.yml b/tasks/elastic-install.yml index e4746b0..47359e5 100644 --- a/tasks/elastic-install.yml +++ b/tasks/elastic-install.yml @@ -6,12 +6,14 @@ state=present update_cache=yes cache_valid_time={{apt_cache_valid_time}} + when: ansible_distribution == "Ubuntu" - name: elastic-install | Install dependencies - apt: - pkg={{ item }} - state=present - with_items: elasticsearch_apt_dependencies + action: > + {{ ansible_pkg_mgr }} + name={{ item }} + state=present + with_items: "{{ elasticsearch_pkg_dependencies }}" - name: elastic-install | Configuring elastic group group: @@ -45,14 +47,26 @@ - name: elastic-install | Download Elasticsearch deb get_url: - url={{ elasticsearch_download_url }}/elasticsearch-{{ elasticsearch_version }}.deb - dest=/tmp/elasticsearch-{{ elasticsearch_version }}.deb + url={{ elasticsearch_ubuntu_download_url }} + dest=/tmp/ mode=0440 - when: not installed_version.stat.exists + register: downloaded_pkg + when: not installed_version.stat.exists and + ansible_distribution == "Ubuntu" + +- name: elastic-install | Download Elasticsearch rpm + get_url: + url={{ elasticsearch_centos7_download_url }} + dest=/tmp/ + mode=0440 + register: downloaded_pkg + when: not installed_version.stat.exists and + ansible_distribution == "CentOS" and + ansible_distribution_major_version == "7" -#shell: dpkg --remove elasticsearch - name: elastic-install | Uninstalling previous version if applicable - apt: + action: > + {{ ansible_pkg_mgr }} name="elasticsearch" state="absent" when: not installed_version.stat.exists @@ -63,9 +77,17 @@ state=absent when: not installed_version.stat.exists -- name: elastic-install | Install Elasticsearch deb - shell: dpkg -i -E --force-confnew /tmp/elasticsearch-{{ elasticsearch_version }}.deb - when: not installed_version.stat.exists +- name: elastic-install | Ubuntu | Install Elasticsearch deb + shell: dpkg -i -E --force-confnew {{ downloaded_pkg.dest }} + when: not installed_version.stat.exists and + ansible_distribution == "Ubuntu" + notify: Restart Elasticsearch + +- name: elastic-install | CentOS-7 | Install Elasticsearch rpm + shell: rpm -i {{ downloaded_pkg.dest }} + when: not installed_version.stat.exists and + ansible_distribution == "CentOS" and + ansible_distribution_major_version == "7" notify: Restart Elasticsearch - name: elastic-install | Ensure elastic directories exists @@ -83,7 +105,7 @@ - "{{ elasticsearch_work_dir }}" - "{{ elasticsearch_conf_dir }}" -- name: Configure limits max_open_files +- name: elastic-install | Configure limits max_open_files lineinfile: dest=/etc/security/limits.conf regexp='^{{ elasticsearch_user }} - nofile {{ elasticsearch_max_open_files }}' @@ -116,6 +138,7 @@ insertafter=EOF line='session required pam_limits.so' notify: Restart Elasticsearch + when: ansible_distribution == "Ubuntu" - name: elastic-install | Configure common-session-noninteractive pam_limits.so lineinfile: @@ -124,6 +147,17 @@ insertafter=EOF line='session required pam_limits.so' notify: Restart Elasticsearch + when: ansible_distribution == "Ubuntu" + +- name: elastic-install | Configure system-auth pam_limits.so + lineinfile: + dest=/etc/pam.d/system-auth + regexp='^session required pam_limits.so' + insertafter=EOF + line='session required pam_limits.so' + notify: Restart Elasticsearch + when: ansible_distribution == "CentOS" and + ansible_distribution_major_version == "7" - name: elastic-install | Configure sudo pam_limits.so lineinfile: @@ -158,4 +192,4 @@ owner={{ elasticsearch_user }} group={{ elasticsearch_group }} mode=0644 - notify: Restart Elasticsearch \ No newline at end of file + notify: Restart Elasticsearch diff --git a/tasks/java.yml b/tasks/java.yml index 7fdff49..b4b627f 100644 --- a/tasks/java.yml +++ b/tasks/java.yml @@ -3,6 +3,7 @@ - name: java | Accept Oracle license prior JDK installation shell: echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections; echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections creates=/usr/lib/jvm/java-8-oracle + when: ansible_distribution == "Ubuntu" - name: java | Update repositories apt_repository: @@ -10,8 +11,10 @@ state=present update_cache=yes with_items: elasticsearch_apt_repos + when: ansible_distribution == "Ubuntu" - name: java | Install dependencies - apt: - pkg={{elasticsearch_apt_java_package}} + action: > + {{ansible_pkg_mgr}} + name={{elasticsearch_java_package}} state=present diff --git a/tasks/main.yml b/tasks/main.yml index f34a5b8..0d93c93 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,28 +4,45 @@ # Install Java - include: java.yml when: elasticsearch_install_java + tags: + - java # Configure timezome - include: timezone.yml + tags: + - timezone # Install and configure elasticsearch - include: elastic-install.yml + tags: + - install # Install AWS Plugin - include: aws.yml when: (elasticsearch_plugin_aws_version is defined) + tags: + - aws + - plugins # Install Other Generic Plugins - include: plugins.yml when: (elasticsearch_plugins is defined) + tags: + - plugins # Install custom JARs - include: custom-jars.yml when: (elasticsearch_custom_jars is defined) + tags: + - java + - custom-jars # Install Marvel Plugin - include: marvel.yml when: (elasticsearch_plugin_marvel_version is defined) + tags: + - marvel + - plugins # Always run post-run tasks - include: post-run.yml diff --git a/tasks/plugins.yml b/tasks/plugins.yml index 0c14aec..7f6b183 100644 --- a/tasks/plugins.yml +++ b/tasks/plugins.yml @@ -35,7 +35,7 @@ with_items: elasticsearch_plugins ignore_errors: yes - name: plugins | Installing Plugins - shell: bin/plugin -install {{ item.name }} {{ '-url ' + item.url if item.url is defined else '' }} + shell: bin/plugin install {{ item.name }} {{ '-url ' + item.url if item.url is defined else '' }} chdir={{ elasticsearch_home_dir }} when: item.download_only is not defined with_items: elasticsearch_plugins diff --git a/tasks/spm.yml b/tasks/spm.yml index 72f3cf4..9c7dd5d 100644 --- a/tasks/spm.yml +++ b/tasks/spm.yml @@ -2,9 +2,10 @@ # SPM Tasks (see http://sematext.com/spm/) - name: spm | Install Collectd - apt: - pkg=collectd - state=present + action: > + {{ansible_pkg_mgr}} + pkg=collectd + state=present # TODO: Make idempotent - name: spm | Downloading and running package diff --git a/tests/test1_var.yml b/tests/test1_var.yml index 0b25bf8..4860d50 100644 --- a/tests/test1_var.yml +++ b/tests/test1_var.yml @@ -1,7 +1,7 @@ --- elasticsearch_version: 1.4.2 -elasticsearch_apt_java_package: oracle-java8-installer +elasticsearch_java_package: oracle-java8-installer elasticsearch_java_home: /usr/lib/jvm/java-8-oracle elasticsearch_heap_size: 1g elasticsearch_max_open_files: 65535