diff --git a/states/_runners/process_minion_data.py b/states/_runners/process_minion_data.py index 8503982..ace7354 100755 --- a/states/_runners/process_minion_data.py +++ b/states/_runners/process_minion_data.py @@ -1,10 +1,9 @@ -#!/usr/pkg/bin/python2 -#-*- coding: utf-8 -*- +#!/usr/bin/python3 -import os +import sys import subprocess -import salt.modules.smtp import json +import salt.modules.smtp ''' For use with salt reactor @@ -17,7 +16,7 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server): try: if type(data['return']) is dict: - for state, result in data['return'].iteritems(): + for _, result in data['return'].iteritems(): if not result['result']: error = True break @@ -27,25 +26,29 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server): else: if not data['success']: error = True - except KeyError as e: - exit() + except KeyError: + sys.exit() - #if error or changes: - if error: - js = subprocess.check_output(["salt-run", "--out=json", "jobs.lookup_jid", data['jid']]) + if error or changes: + _js = subprocess.check_output(["salt-run", "--out=json", + "jobs.lookup_jid", data['jid']]) body = "JobId is %s\n" % (data['jid']) - outdata = json.loads(js) + outdata = json.loads(_js) nodename = outdata.keys()[0] for i in outdata[nodename]: if not outdata[nodename][i]["result"]: - name = outdata[nodename][i]["name"] + name = outdata[nodename][i]["name"] comment = outdata[nodename][i]["comment"].rstrip('\n') data = "%s- %s / %s\n" % (body, name, comment) - salt.modules.smtp.send_msg(recipient=toaddrs, message=data, subject=subject, sender=fromaddr, server=smtp_server, use_ssl=False) + salt.modules.smtp.send_msg(recipient=toaddrs, message=data, + subject=subject, sender=fromaddr, + server=smtp_server, use_ssl=False) return True def email_auth(fromaddr, toaddrs, subject, data_str, smtp_server): data = eval(data_str) - salt.modules.smtp.send_msg(recipient=toaddrs, message=data, subject=subject, sender=fromaddr, server=smtp_server, use_ssl=False) + salt.modules.smtp.send_msg(recipient=toaddrs, message=data, + subject=subject, sender=fromaddr, + server=smtp_server, use_ssl=False) - return True \ No newline at end of file + return True diff --git a/states/_states/custom.py b/states/_states/custom.py index caa0e1a..4824f50 100755 --- a/states/_states/custom.py +++ b/states/_states/custom.py @@ -33,7 +33,7 @@ def enforce_custom_thing(name, foo, bar=True): # Start with basic error-checking. Do all the passed parameters make sense # and agree with each-other? - if bar == True and foo.startswith('Foo'): + if bar and foo.startswith('Foo'): raise salt.exceptions.SaltInvocationError( 'Argument "foo" cannot start with "Foo" if argument "bar" is True.') @@ -71,4 +71,4 @@ def enforce_custom_thing(name, foo, bar=True): ret['result'] = True - return ret \ No newline at end of file + return ret diff --git a/states/_states/dkron.py b/states/_states/dkron.py index 6cdaf91..3804bb5 100644 --- a/states/_states/dkron.py +++ b/states/_states/dkron.py @@ -4,16 +4,16 @@ from __future__ import absolute_import, print_function, unicode_literals import salt.utils.dictupdate import salt.utils.dictdiffer -def jobs(name, url="http://localhost:8080", verify=False, jobs=[]): +def jobs(name, url="http://localhost:8080", verify=False, job_list=[]): ret = {'name': name, - 'changes': {}, - 'result': True, - 'comment': 'Config is up to date'} + 'changes': {}, + 'result': True, + 'comment': 'Config is up to date'} #dk_jobs = [] #dk_jobs = __salt__['dkron.get_jobs'](url, verify) - for job in jobs: + for job in job_list: res = __salt__['dkron.set_jobs'](url, verify, job) if res is not None: ret['changes'][job['name']] = res diff --git a/states/_states/syncthing.py b/states/_states/syncthing.py index 197510a..e0944dd 100644 --- a/states/_states/syncthing.py +++ b/states/_states/syncthing.py @@ -6,9 +6,9 @@ import salt.utils.dictdiffer def config(name, verify, url, cfg): ret = {'name': name, - 'changes': {}, - 'result': True, - 'comment': 'config is up to date'} + 'changes': {}, + 'result': True, + 'comment': 'config is up to date'} cfg = dict(cfg) @@ -24,4 +24,4 @@ def config(name, verify, url, cfg): ret['changes'] = salt.utils.dictdiffer.deep_diff(st_cfg, res_cfg) - return ret \ No newline at end of file + return ret diff --git a/states/cds/telegraf.service.j2 b/states/cds/telegraf.service.j2 deleted file mode 100644 index 4d95d40..0000000 --- a/states/cds/telegraf.service.j2 +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=The plugin-driven server agent for reporting metrics into InfluxDB -Documentation=https://github.com/influxdata/telegraf -After=network.target - -[Service] -EnvironmentFile=-/etc/default/telegraf -#User=telegraf -ExecStart=/usr/bin/telegraf --config $INFLUX_CONFIG -ExecReload=/bin/kill -HUP $MAINPID -Restart=on-failure -RestartForceExitStatus=SIGPIPE -KillMode=control-group - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/states/dkron/jobs.sls b/states/dkron/jobs.sls index 7441ff4..d434a30 100644 --- a/states/dkron/jobs.sls +++ b/states/dkron/jobs.sls @@ -5,4 +5,4 @@ dkron-jobs: - name: dkron-jobs - url: {{ dkron.url }} - verify: {{ dkron.verify }} - - jobs: {{ dkron.jobs }} \ No newline at end of file + - job_list: {{ dkron.job_list }}