fixed linting errors by refactoring ansible tests and change a variable name

This commit is contained in:
rshad 2019-07-24 10:49:17 +00:00
parent 8575aecc88
commit fcb584ab20
3 changed files with 49 additions and 32 deletions

View File

@ -3,7 +3,7 @@ elasticsearch_cluster_name: wazuh
elasticsearch_node_name: node-1 elasticsearch_node_name: node-1
elasticsearch_http_port: 9200 elasticsearch_http_port: 9200
elasticsearch_network_host: 0.0.0.0 elasticsearch_network_host: 0.0.0.0
elasticsearch_check_connection: 127.0.0.1 elasticsearch_host: 127.0.0.1
elasticsearch_jvm_xms: null elasticsearch_jvm_xms: null
elastic_stack_version: 7.2.0 elastic_stack_version: 7.2.0
single_node: false single_node: false

View File

@ -26,7 +26,7 @@
- name: Install Oracle Java 8 - name: Install Oracle Java 8
become: true become: true
apt: name=openjdk-8-jdk state=latest apt: name=openjdk-8-jdk
when: when:
- ansible_distribution == "Ubuntu" - ansible_distribution == "Ubuntu"

View File

@ -65,7 +65,7 @@
- name: Check if certificate exists locally - name: Check if certificate exists locally
stat: stat:
path: "{{node_certs_destination}}/{{ elasticsearch_node_name }}.crt" path: "{{ node_certs_destination }}/{{ elasticsearch_node_name }}.crt"
register: certificate_file_exists register: certificate_file_exists
when: when:
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -73,7 +73,7 @@
- name: Write the instances.yml file in the selected node (force = no) - name: Write the instances.yml file in the selected node (force = no)
template: template:
src: instances.yml.j2 src: instances.yml.j2
dest: "{{node_certs_source}}/instances.yml" dest: "{{ node_certs_source }}/instances.yml"
force: no force: no
register: instances_file_exists register: instances_file_exists
tags: tags:
@ -86,7 +86,7 @@
- name: Update instances.yml status after generation - name: Update instances.yml status after generation
stat: stat:
path: "{{node_certs_source}}/instances.yml" path: "{{ node_certs_source }}/instances.yml"
register: instances_file_exists register: instances_file_exists
when: when:
- node_certs_generator - node_certs_generator
@ -94,14 +94,16 @@
- name: Check if the certificates ZIP file exists - name: Check if the certificates ZIP file exists
stat: stat:
path: "{{node_certs_source}}/certs.zip" path: "{{ node_certs_source }}/certs.zip"
register: xpack_certs_zip register: xpack_certs_zip
when: when:
- node_certs_generator - node_certs_generator
- elasticsearch_xpack_security - elasticsearch_xpack_security
- name: Generating certificates for Elasticsearch security - name: Generating certificates for Elasticsearch security
shell: "/usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in {{node_certs_source}}/instances.yml --out {{node_certs_source}}/certs.zip" command: >-
"/usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in
{{ node_certs_source }}/instances.yml --out {{ node_certs_source }}/certs.zip"
when: when:
- node_certs_generator - node_certs_generator
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -112,8 +114,8 @@
- name: Unzip generated certs.zip - name: Unzip generated certs.zip
unarchive: unarchive:
src: "{{node_certs_source}}/certs.zip" src: "{{ node_certs_source }}/certs.zip"
dest: "{{node_certs_source}}/" dest: "{{ node_certs_source }}/"
remote_src: yes remote_src: yes
when: when:
- node_certs_generator - node_certs_generator
@ -124,8 +126,8 @@
- name: Copy key & certificate files in generator node (locally) - name: Copy key & certificate files in generator node (locally)
synchronize: synchronize:
src: "{{node_certs_source}}/{{elasticsearch_node_name}}/" src: "{{ node_certs_source }}/{{ elasticsearch_node_name }}/"
dest: "{{node_certs_destination}}/" dest: "{{ node_certs_destination }}/"
delegate_to: "{{ node_certs_generator_ip }}" delegate_to: "{{ node_certs_generator_ip }}"
when: when:
- node_certs_generator - node_certs_generator
@ -134,8 +136,8 @@
- name: Copy ca certificate file in generator node (locally) - name: Copy ca certificate file in generator node (locally)
synchronize: synchronize:
src: "{{node_certs_source}}/ca/" src: "{{ node_certs_source }}/ca/"
dest: "{{node_certs_destination}}/" dest: "{{ node_certs_destination }}/"
delegate_to: "{{ node_certs_generator_ip }}" delegate_to: "{{ node_certs_generator_ip }}"
register: check_certs_permissions register: check_certs_permissions
when: when:
@ -144,7 +146,9 @@
tags: xpack-security tags: xpack-security
- name: Importing key & certificate files from generator node - name: Importing key & certificate files from generator node
shell: "{{rsync_path}} {{rsync_extra_parameters}} {{rsync_user}}@{{node_certs_generator_ip}}:{{node_certs_source}}/{{elasticsearch_node_name}}/ {{node_certs_destination}}/" command: >-
{{ rsync_path }} {{ rsync_extra_parameters }} {{ rsync_user }}@{{ node_certs_generator_ip }}:
{{ node_certs_source }}/{{ elasticsearch_node_name }}/ {{ node_certs_destination }}/
when: when:
- not node_certs_generator - not node_certs_generator
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -152,7 +156,9 @@
tags: xpack-security tags: xpack-security
- name: Importing ca certificate file from generator node - name: Importing ca certificate file from generator node
shell: "{{rsync_path}} {{rsync_extra_parameters}} {{rsync_user}}@{{node_certs_generator_ip}}:{{node_certs_source}}/ca/ {{node_certs_destination}}/" command: >-
{{ rsync_path }} {{ rsync_extra_parameters }} {{ rsync_user }}@{{ node_certs_generator_ip }}:
{{ node_certs_source }}/ca/ {{ node_certs_destination }}/
when: when:
- not node_certs_generator - not node_certs_generator
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -161,22 +167,31 @@
tags: xpack-security tags: xpack-security
- name: Ensuring certificates folder owner - name: Ensuring certificates folder owner
shell: "chown -R elasticsearch: {{node_certs_destination}}/" file:
path: "{{ node_certs_destination }}/"
state: directory
recurse: yes
owner: elasticsearch
group: elasticsearch
when: when:
- check_certs_permissions is defined - check_certs_permissions is defined
- elasticsearch_xpack_security - elasticsearch_xpack_security
tags: xpack-security tags: xpack-security
- name: Ensuring certificates folder owner - name: Ensuring certificates folder owner
shell: "chmod -R 770 {{node_certs_destination}}/" file:
path: "{{ node_certs_destination }}/"
mode: '0770'
recurse: yes
when: when:
- check_certs_permissions is defined - check_certs_permissions is defined
- elasticsearch_xpack_security - elasticsearch_xpack_security
tags: xpack-security tags: xpack-security
- name: Remove generated certs file - name: Remove generated certs file
shell: /bin/rm -f {{node_certs_source}}/certs.zip* file:
state: absent
path: "{{ node_certs_source }}/certs.zip*"
when: when:
- node_certs_generator - node_certs_generator
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -193,7 +208,9 @@
tags: configure tags: configure
- name: Set elasticsearch bootstrap password - name: Set elasticsearch bootstrap password
shell: "echo '{{elasticsearch_xpack_security_password}}' | {{node_certs_source}}/bin/elasticsearch-keystore add -xf 'bootstrap.password'" shell: |
set -o pipefail
"echo '{{ elasticsearch_xpack_security_password }}' | {{ node_certs_source }}/bin/elasticsearch-keystore add -xf 'bootstrap.password'"
when: when:
- elasticsearch_xpack_security - elasticsearch_xpack_security
@ -242,7 +259,7 @@
state: started state: started
- name: Make sure Elasticsearch is running before proceeding - name: Make sure Elasticsearch is running before proceeding
wait_for: host={{ elasticsearch_check_connection }} port={{ elasticsearch_http_port }} delay=3 timeout=400 wait_for: host={{ elasticsearch_host }} port={{ elasticsearch_http_port }} delay=3 timeout=400
tags: tags:
- configure - configure
- init - init