2017-01-11 13:02:23 +00:00
---
#Security specific configuration done here
#TODO: 1. Skip users with no password defined or error 2. Passwords | length > 6
2017-04-18 13:26:16 -04:00
#Ensure x-pack conf directory is created if necessary
- name : Ensure x-pack conf directory exists (file)
2019-06-03 14:18:09 +02:00
file : path={{ es_conf_dir }}{{ es_xpack_conf_subdir }} state=directory owner={{ es_user }} group={{ es_group }}
2017-04-18 13:26:16 -04:00
changed_when : False
2019-05-29 12:10:11 +02:00
when : (es_users is defined and es_users.file is defined) or (es_roles is defined and es_roles.file is defined) or (es_role_mapping is defined)
2017-04-18 13:26:16 -04:00
2018-01-08 16:59:44 -08:00
#-----------------------------Create Bootstrap User-----------------------------------
2018-06-13 17:33:23 +02:00
### START BLOCK elasticsearch keystore ###
- name : create the elasticsearch keystore
block :
- name : create the keystore if it doesn't exist yet
2018-06-26 15:13:19 -04:00
become : yes
2018-06-13 17:33:23 +02:00
command : >
{{es_home}}/bin/elasticsearch-keystore create
2018-06-14 14:44:31 +02:00
args :
2019-06-03 14:18:09 +02:00
creates : "{{ es_conf_dir }}/elasticsearch.keystore"
2018-06-13 17:33:23 +02:00
environment :
2019-06-03 14:18:09 +02:00
ES_PATH_CONF : "{{ es_conf_dir }}"
2018-06-26 15:13:19 -04:00
2018-06-13 17:33:23 +02:00
- name : Check if bootstrap password is set
2018-06-26 15:13:19 -04:00
become : yes
2018-06-13 17:33:23 +02:00
command : >
{{es_home}}/bin/elasticsearch-keystore list
register : list_keystore
changed_when : False
environment :
2019-06-03 14:18:09 +02:00
ES_PATH_CONF : "{{ es_conf_dir }}"
2019-03-14 09:23:24 +01:00
check_mode : no
2018-01-08 16:59:44 -08:00
2018-06-13 17:33:23 +02:00
- name : Create Bootstrap password for elastic user
2018-06-26 15:13:19 -04:00
become : yes
2018-06-13 17:33:23 +02:00
shell : echo "{{es_api_basic_auth_password}}" | {{es_home}}/bin/elasticsearch-keystore add -x 'bootstrap.password'
when :
- es_api_basic_auth_username is defined and list_keystore is defined and es_api_basic_auth_username == 'elastic' and 'bootstrap.password' not in list_keystore.stdout_lines
environment :
2019-06-03 14:18:09 +02:00
ES_PATH_CONF : "{{ es_conf_dir }}"
2018-06-13 17:33:23 +02:00
no_log : true
### END BLOCK elasticsearch keystore ###
2018-01-08 16:59:44 -08:00
2017-01-11 13:02:23 +00:00
#-----------------------------FILE BASED REALM----------------------------------------
- include : elasticsearch-security-file.yml
2019-05-29 12:10:11 +02:00
when : (es_users is defined and es_users.file is defined) or (es_roles is defined and es_roles.file is defined)
2017-01-11 13:02:23 +00:00
#-----------------------------ROLE MAPPING ----------------------------------------
#Copy Roles files
- name : Copy role_mapping.yml File for Instance
2017-05-12 13:31:50 -07:00
become : yes
2019-06-03 14:18:09 +02:00
template : src=security/role_mapping.yml.j2 dest={{ es_conf_dir }}{{es_xpack_conf_subdir}}/role_mapping.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
2017-01-11 13:02:23 +00:00
when : es_role_mapping is defined
#------------------------------------------------------------------------------------
#Ensure security conf directory is created
- name : Ensure security conf directory exists
2017-05-12 13:31:50 -07:00
become : yes
2019-06-03 14:18:09 +02:00
file : path={{ es_conf_dir }}/security state=directory owner={{ es_user }} group={{ es_group }}
2017-01-11 13:02:23 +00:00
changed_when : False