2016-07-22 23:44:27 +01:00
---
2018-02-04 07:09:23 +00:00
- name : set fact manage_file_users
2019-06-07 15:54:10 +02:00
set_fact : manage_file_users=es_users is defined and es_users.file is defined and es_users.file.keys() | list | length > 0
2016-07-22 23:44:27 +01:00
2018-11-27 12:50:49 +01:00
- name : Check if old users file exists
stat :
2019-06-03 14:18:09 +02:00
path : '{{ es_conf_dir }}/x-pack/users'
2018-11-27 12:50:49 +01:00
register : old_users_file
2019-03-14 09:23:24 +01:00
check_mode : no
2018-11-27 12:50:49 +01:00
2018-11-26 13:56:51 +01:00
- name : Copy the old users file from the old depreacted location
copy :
remote_src : yes
force : no # only copy it if the new path doesn't exist yet
2019-06-03 14:18:09 +02:00
src : "{{ es_conf_dir }}/x-pack/users"
dest : "{{ es_conf_dir }}{{ es_xpack_conf_subdir }}/users"
2018-11-27 12:50:49 +01:00
when : old_users_file.stat.exists
2018-11-26 13:56:51 +01:00
2018-06-14 16:33:40 +02:00
- name : Create the users file if it doesn't exist
copy :
content : ""
2019-06-03 14:18:09 +02:00
dest : "{{ es_conf_dir }}{{ es_xpack_conf_subdir }}/users"
2018-06-14 16:33:40 +02:00
force : no # this ensures it only creates it if it does not exist
group : "{{ es_group }}"
owner : "{{ es_user }}"
mode : 0555
2016-07-22 23:44:27 +01:00
#List current users
- name : List Users
2017-05-12 13:31:50 -07:00
become : yes
2019-06-03 14:18:09 +02:00
shell : cat {{ es_conf_dir }}{{es_xpack_conf_subdir}}/users | awk -F':' '{print $1}'
2016-07-22 23:44:27 +01:00
register : current_file_users
when : manage_file_users
2016-07-23 16:41:37 +01:00
changed_when : False
2019-03-14 09:23:24 +01:00
check_mode : no
2016-07-22 23:44:27 +01:00
2018-02-04 07:09:23 +00:00
- name : set fact users_to_remove
2019-06-07 15:54:10 +02:00
set_fact : users_to_remove={{ current_file_users.stdout_lines | difference (es_users.file.keys() | list) }}
2016-07-22 23:44:27 +01:00
when : manage_file_users
#Remove users
- name : Remove Users
2017-05-12 13:31:50 -07:00
become : yes
2016-07-22 23:44:27 +01:00
command : >
2018-06-14 14:44:31 +02:00
{{es_home}}/bin/{{es_xpack_users_command}} userdel {{item}}
2016-11-02 15:02:51 +01:00
with_items : "{{users_to_remove | default([])}}"
2017-09-20 22:58:17 +01:00
when : manage_file_users
2016-07-22 23:44:27 +01:00
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
2016-07-22 23:44:27 +01:00
ES_HOME : "{{es_home}}"
2018-02-04 07:09:23 +00:00
- name : set fact users_to_add
2019-06-07 15:54:10 +02:00
set_fact : users_to_add={{ es_users.file.keys() | list | difference (current_file_users.stdout_lines) }}
2016-07-23 16:41:37 +01:00
when : manage_file_users
2016-07-22 23:44:27 +01:00
#Add users
- name : Add Users
2017-05-12 13:31:50 -07:00
become : yes
2016-07-22 23:44:27 +01:00
command : >
2018-06-14 14:44:31 +02:00
{{es_home}}/bin/{{es_xpack_users_command}} useradd {{item}} -p {{es_users.file[item].password}}
2017-09-20 22:58:17 +01:00
with_items : "{{ users_to_add | default([]) }}"
when : manage_file_users
2016-09-19 17:41:24 +02:00
no_log : True
2016-07-22 23:44:27 +01:00
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
2016-07-22 23:44:27 +01:00
ES_HOME : "{{es_home}}"
#Set passwords for all users declared - Required as the useradd will not change existing user passwords
- name : Set User Passwords
2017-05-12 13:31:50 -07:00
become : yes
2016-07-22 23:44:27 +01:00
command : >
2018-06-14 14:44:31 +02:00
{{es_home}}/bin/{{es_xpack_users_command}} passwd {{ item }} -p {{es_users.file[item].password}}
2019-06-07 15:54:10 +02:00
with_items : "{{ es_users.file.keys() | list }}"
2017-09-20 22:58:17 +01:00
when : manage_file_users
2016-07-23 16:41:37 +01:00
#Currently no easy way to figure out if the password has changed or to know what it currently is so we can skip.
changed_when : False
2018-06-14 16:37:31 +02:00
no_log : True
2016-07-22 23:44:27 +01:00
environment :
2019-06-03 14:18:09 +02:00
CONF_DIR : "{{ es_conf_dir }}"
ES_PATH_CONF : "{{ es_conf_dir }}"
2016-07-22 23:44:27 +01:00
ES_HOME : "{{es_home}}"
2018-02-04 07:09:23 +00:00
- name : set fact users_roles
set_fact : users_roles={{es_users.file | extract_role_users () }}
2016-07-22 23:44:27 +01:00
when : manage_file_users
#Copy Roles files
- name : Copy roles.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/roles.yml.j2 dest={{ es_conf_dir }}{{es_xpack_conf_subdir}}/roles.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
2016-07-22 23:44:27 +01:00
when : es_roles is defined and es_roles.file is defined
#Overwrite users_roles file
- name : Copy User Roles
2017-05-12 13:31:50 -07:00
become : yes
2019-06-03 14:18:09 +02:00
template : src=security/users_roles.j2 dest={{ es_conf_dir }}{{es_xpack_conf_subdir}}/users_roles mode=0644 force=yes
2016-07-22 23:44:27 +01:00
when : manage_file_users and users_roles | length > 0
2017-01-11 13:02:23 +00:00
#Set permission on security directory. E.g. if 2 nodes are installed on the same machine, the second node will not get the users file created at install, causing the files being created at es_users call and then having the wrong Permissions.
- name : Set Security Directory Permissions Recursive
2017-05-12 13:31:50 -07:00
become : yes
2019-06-03 14:18:09 +02:00
file : state=directory path={{ es_conf_dir }}{{es_xpack_conf_subdir}}/ owner={{ es_user }} group={{ es_group }} recurse=yes