summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Woodson <mwoodson@gmail.com>2015-08-20 12:18:49 -0400
committerMatt Woodson <mwoodson@gmail.com>2015-08-20 12:18:49 -0400
commit2f5486c7174eeacdd52938442daa2ddfa6a8e277 (patch)
treea11bb5df45b188021b733d6fdab785d9a5604ff5
parenta473ade355c72b45bff57f01ecd8898725977405 (diff)
parent49923edfba6d396140881d6a920e83f9ecf79f77 (diff)
downloadopenshift-2f5486c7174eeacdd52938442daa2ddfa6a8e277.tar.gz
openshift-2f5486c7174eeacdd52938442daa2ddfa6a8e277.tar.bz2
openshift-2f5486c7174eeacdd52938442daa2ddfa6a8e277.tar.xz
openshift-2f5486c7174eeacdd52938442daa2ddfa6a8e277.zip
Merge pull request #496 from kwoodson/zbxsetup
Playbook for updating users during zabbix setup.
-rw-r--r--playbooks/adhoc/zabbix_setup/create_user.yml31
-rw-r--r--roles/os_zabbix/library/zbx_user.py13
2 files changed, 40 insertions, 4 deletions
diff --git a/playbooks/adhoc/zabbix_setup/create_user.yml b/playbooks/adhoc/zabbix_setup/create_user.yml
new file mode 100644
index 000000000..dd74798b7
--- /dev/null
+++ b/playbooks/adhoc/zabbix_setup/create_user.yml
@@ -0,0 +1,31 @@
+---
+# export PYTHONPATH='/usr/lib/python2.7/site-packages/:/home/kwoodson/git/openshift-tools'
+# ansible-playbook -e 'cli_password=zabbix' -e 'cli_new_password=new-zabbix' create_user.yml
+- hosts: localhost
+ gather_facts: no
+ vars_files:
+ - vars/template_heartbeat.yml
+ - vars/template_os_linux.yml
+ vars:
+ g_zserver: http://localhost/zabbix/api_jsonrpc.php
+ g_zuser: admin
+ g_zpassword: "{{ cli_password }}"
+ roles:
+ - ../../../roles/os_zabbix
+ post_tasks:
+ - zbx_user:
+ server: "{{ g_zserver }}"
+ user: "{{ g_zuser }}"
+ password: "{{ g_zpassword }}"
+ state: list
+ register: users
+
+ - debug: var=users
+
+ - name: Update zabbix creds for admin
+ zbx_user:
+ server: "{{ g_zserver }}"
+ user: "{{ g_zuser }}"
+ password: "{{ g_zpassword }}"
+ alias: Admin
+ passwd: "{{ cli_new_password | default(g_zpassword, true) }}"
diff --git a/roles/os_zabbix/library/zbx_user.py b/roles/os_zabbix/library/zbx_user.py
index 50f6fc075..c45c9a75d 100644
--- a/roles/os_zabbix/library/zbx_user.py
+++ b/roles/os_zabbix/library/zbx_user.py
@@ -54,13 +54,15 @@ def get_usergroups(zapi, usergroups):
if content['result']:
ugroups.append({'usrgrpid': content['result'][0]['usrgrpid']})
- return ugroups
-
+ return ugroups or None
def get_usertype(user_type):
'''
Determine zabbix user account type
'''
+ if not user_type:
+ return None
+
utype = 1
if 'super' in user_type:
utype = 3
@@ -84,9 +86,9 @@ def main():
alias=dict(default=None, type='str'),
name=dict(default=None, type='str'),
surname=dict(default=None, type='str'),
- user_type=dict(default='user', type='str'),
+ user_type=dict(default=None, type='str'),
passwd=dict(default=None, type='str'),
- usergroups=dict(default=None, type='list'),
+ usergroups=dict(default=[], type='list'),
debug=dict(default=False, type='bool'),
state=dict(default='present', type='str'),
),
@@ -129,6 +131,9 @@ def main():
'type': get_usertype(module.params['user_type']),
}
+ # Remove any None valued params
+ _ = [params.pop(key, None) for key in params.keys() if params[key] is None]
+
if not exists(content):
# if we didn't find it, create it
content = zapi.get_content(zbx_class_name, 'create', params)