diff options
-rw-r--r-- | README_AWS.md | 4 | ||||
-rwxr-xr-x | bin/cluster | 23 | ||||
-rw-r--r-- | playbooks/adhoc/noc/create_maintenance.yml | 36 | ||||
-rw-r--r-- | playbooks/adhoc/noc/get_zabbix_problems.yml | 2 |
4 files changed, 57 insertions, 8 deletions
diff --git a/README_AWS.md b/README_AWS.md index 7f4b1832b..5db36b5cb 100644 --- a/README_AWS.md +++ b/README_AWS.md @@ -27,10 +27,10 @@ In case of a cluster creation, or any other case where you don't know the machin to setup a private key file to allow ansible to connect to the created hosts. To do so, add the the following entry to your $HOME/.ssh/config file and make it point to the private key file which allows you to login on AWS. -''' +``` Host *.compute-1.amazonaws.com PrivateKey $HOME/.ssh/my_private_key.pem -''' +``` Alternatively, you can configure your ssh-agent to hold the credentials to connect to your AWS instances. diff --git a/bin/cluster b/bin/cluster index 2ea389523..cb8ff0439 100755 --- a/bin/cluster +++ b/bin/cluster @@ -3,8 +3,9 @@ import argparse import ConfigParser -import sys import os +import sys +import traceback class Cluster(object): @@ -141,6 +142,11 @@ class Cluster(object): os.environ[key] = config.get('ec2', key) inventory = '-i inventory/aws/hosts' + + missing = [key for key in ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'] if key not in os.environ] + if len(missing) > 0: + raise ValueError("PROVIDER aws requires {} environment variable(s). See README_AWS.md".format(missing)) + elif 'libvirt' == provider: inventory = '-i inventory/libvirt/hosts' elif 'openstack' == provider: @@ -168,7 +174,7 @@ class Cluster(object): if args.option: for opt in args.option: k, v = opt.split('=', 1) - env['opt_'+k] = v + env['opt_' + k] = v ansible_env = '-e \'{}\''.format( ' '.join(['%s=%s' % (key, value) for (key, value) in env.items()]) @@ -290,7 +296,14 @@ if __name__ == '__main__': sys.stderr.write('\nACTION [update] aborted by user!\n') exit(1) - status = args.func(args) - if status != 0: - sys.stderr.write("ACTION [{}] failed with exit status {}\n".format(args.action, status)) + status = 1 + try: + status = args.func(args) + if status != 0: + sys.stderr.write("ACTION [{}] failed with exit status {}\n".format(args.action, status)) + except Exception, e: + if args.verbose: + traceback.print_exc(file=sys.stderr) + else: + sys.stderr.write("{}\n".format(e)) exit(status) diff --git a/playbooks/adhoc/noc/create_maintenance.yml b/playbooks/adhoc/noc/create_maintenance.yml new file mode 100644 index 000000000..c0ec57ce1 --- /dev/null +++ b/playbooks/adhoc/noc/create_maintenance.yml @@ -0,0 +1,36 @@ +--- +#ansible-playbook -e 'oo_desc=kwoodson test' -e 'oo_name=kwoodson test name' -e 'oo_start=1435715357' -e 'oo_stop=1435718985' -e 'oo_hostids=11549' create_maintenance.yml +- name: 'Create a maintenace object in zabbix' + hosts: localhost + gather_facts: no + roles: + - os_zabbix + vars: + oo_hostids: '' + oo_groupids: '' + post_tasks: + - assert: + that: oo_desc is defined + + - zbxapi: + server: https://noc2.ops.rhcloud.com/zabbix/api_jsonrpc.php + zbx_class: Maintenance + state: present + params: + name: "{{ oo_name }}" + description: "{{ oo_desc }}" + active_since: "{{ oo_start }}" + active_till: "{{ oo_stop }}" + maintenance_type: "0" + output: extend + hostids: "{{ oo_hostids.split(',') | default([]) }}" +#groupids: "{{ oo_groupids.split(',') | default([]) }}" + timeperiods: + - start_time: "{{ oo_start }}" + period: "{{ oo_stop }}" + selectTimeperiods: extend + + register: maintenance + + - debug: var=maintenance + diff --git a/playbooks/adhoc/noc/get_zabbix_problems.yml b/playbooks/adhoc/noc/get_zabbix_problems.yml index 02bffc1d2..4b94fa228 100644 --- a/playbooks/adhoc/noc/get_zabbix_problems.yml +++ b/playbooks/adhoc/noc/get_zabbix_problems.yml @@ -11,7 +11,7 @@ - zbxapi: server: https://noc2.ops.rhcloud.com/zabbix/api_jsonrpc.php zbx_class: Trigger - action: get + state: list params: only_true: true output: extend |