From a812baa242b6ac05473fcb29a8bcddbb271dbd2c Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Fri, 27 Mar 2020 21:48:09 +0100 Subject: [PATCH] fix --- library/elasticsearch_user.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/library/elasticsearch_user.py b/library/elasticsearch_user.py index c42e223..b73a897 100644 --- a/library/elasticsearch_user.py +++ b/library/elasticsearch_user.py @@ -45,9 +45,14 @@ def main(): 'api_url': { 'type': 'str', 'default': 'http://127.0.0.1:9200' }, 'api_user': { 'type': 'str', 'default': None }, 'api_password': { 'type': 'str', 'default': None }, + 'state': { 'type': 'str', 'default': 'present', 'required': True, 'choice': ['absent', 'present'] }, } module = AnsibleModule(argument_spec=fields) changed = False + special_users = [ + 'elastic', 'kibana', 'logstash_system', + 'beats_system', 'apm_system', 'remote_monitoring_user' + ] options = { 'roles': module.params['roles'], @@ -66,7 +71,14 @@ def main(): ) user.get_data() - if module.params['name'] != 'elastic': + if not module.params['name'] in special_users: + if module.params['state'] == 'absent': + if user.exist: + user.delete() + changed = True + + module.exit_json(changed=changed) + if not user.exist or user.has_changed(module.params['roles']): user.create(options) changed = True