Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some "names" and made some tasks idempotent #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
shell: dpkg-query -f='${Version}' -W 'elasticsearch'
register: installed_elasticsearch_version
ignore_errors: yes
check_mode: no # this change was so we can run this role even in Check mode
changed_when: false # this is a discovery task, and shouldn't "change"

- name: Abort when elasticsearch installed version < 1.8 and version >=5 is going to be installed
fail:
Expand Down Expand Up @@ -55,18 +57,20 @@
state: "present"

# Configure user and group
- name: Configuring user and group
- name: Configure group
group:
name: "{{ elasticsearch_group }}"
- user:
- name: Configure user
user:
name: "{{ elasticsearch_user }}"
group: "{{ elasticsearch_group }}"
createhome: "no"

# Check whether we have aleady installed the same version
- shell: if [ -e /usr/share/elasticsearch/lib/elasticsearch-{{ elasticsearch_version }}.jar ]; then echo yes; else echo no; fi;
- name: Check whether we have aleady installed the same version
shell: if [ -e /usr/share/elasticsearch/lib/elasticsearch-{{ elasticsearch_version }}.jar ]; then echo yes; else echo no; fi;
register: version_exists
check_mode: no
changed_when: false # this is a discovery task, and shouldn't "change"

# Download deb if needed (ES version < 5.0.0)
- name: Download Elasticsearch deb (ES version < 5.0.0)
Expand All @@ -82,13 +86,22 @@
- name: Uninstalling previous version if applicable
shell: dpkg --remove elasticsearch
when: version_exists.stdout == 'no'
- file:
path: "/usr/share/elasticsearch"
state: "absent"

- name: Ensure previous version directory is removed if applicable
file:
path: /usr/share/elasticsearch
state: absent
when: version_exists.stdout == 'no'

# Install the deb
- name: Install Elasticsearch deb
shell: dpkg -i -E --force-confnew /tmp/elasticsearch-{{ elasticsearch_version }}.deb
when: version_exists.stdout == 'no'
- file: path=/usr/share/elasticsearch state=directory owner={{ elasticsearch_user }} group={{ elasticsearch_group }} recurse=yes

- name: Change ower/group of Elasticsearch directory
file:
path: /usr/share/elasticsearch
state: directory
owner: "{{ elasticsearch_user }}"
group: "{{ elasticsearch_group }}"
recurse: yes
2 changes: 2 additions & 0 deletions tasks/cve-2021-4104-patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
shell:
cmd: "unzip -l log4j-*.jar | grep JMSAppender.class"
chdir: "/usr/share/elasticsearch/lib"
warn: no # This needs to be a cmd, and not the unzip module
register: "__jmsappender_class"
failed_when: "__jmsappender_class.rc not in [ 0, 1 ]"
changed_when: __jmsappender_class.rc == 0 # Filename should be in output

- name: "Remove JMSAppender.class"
become: "yes"
Expand Down
3 changes: 3 additions & 0 deletions tasks/cve-2021-44228-patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
shell:
cmd: "unzip -l log4j-core-*.jar | grep JndiLookup.class"
chdir: "/usr/share/elasticsearch/lib"
warn: no # This needs to be a cmd, and not the unzip module
register: "__jndulookup_class"
failed_when: "__jndulookup_class.rc not in [ 0, 1 ]"
check_mode: no
changed_when: __jndulookup_class.rc == 0 # Filename should be in output

- name: "Remove JndiLookup.class"
become: "yes"
Expand Down