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