removed syslog in favor of common module logging functions

This commit is contained in:
Brian Coca 2015-10-01 00:12:54 -04:00 committed by Matt Clay
parent 682cb99d45
commit d55ba3ab7c
6 changed files with 12 additions and 56 deletions

View file

@ -61,7 +61,6 @@ EXAMPLES = '''
- rpm_key: state=absent key=DEADB33F - rpm_key: state=absent key=DEADB33F
''' '''
import re import re
import syslog
import os.path import os.path
import urllib2 import urllib2
import tempfile import tempfile
@ -74,7 +73,6 @@ def is_pubkey(string):
class RpmKey: class RpmKey:
def __init__(self, module): def __init__(self, module):
self.syslogging = False
# If the key is a url, we need to check if it's present to be idempotent, # If the key is a url, we need to check if it's present to be idempotent,
# to do that, we need to check the keyid, which we can get from the armor. # to do that, we need to check the keyid, which we can get from the armor.
keyfile = None keyfile = None
@ -163,9 +161,6 @@ class RpmKey:
return re.match('(0x)?[0-9a-f]{8}', keystr, flags=re.IGNORECASE) return re.match('(0x)?[0-9a-f]{8}', keystr, flags=re.IGNORECASE)
def execute_command(self, cmd): def execute_command(self, cmd):
if self.syslogging:
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Command %s' % '|'.join(cmd))
rc, stdout, stderr = self.module.run_command(cmd) rc, stdout, stderr = self.module.run_command(cmd)
if rc != 0: if rc != 0:
self.module.fail_json(msg=stderr) self.module.fail_json(msg=stderr)

View file

@ -26,7 +26,6 @@ import traceback
import os import os
import yum import yum
import rpm import rpm
import syslog
import platform import platform
import tempfile import tempfile
import shutil import shutil
@ -169,10 +168,6 @@ BUFSIZE = 65536
def_qf = "%{name}-%{version}-%{release}.%{arch}" def_qf = "%{name}-%{version}-%{release}.%{arch}"
def log(msg):
syslog.openlog('ansible-yum', 0, syslog.LOG_USER)
syslog.syslog(syslog.LOG_NOTICE, msg)
def yum_base(conf_file=None): def yum_base(conf_file=None):
my = yum.YumBase() my = yum.YumBase()

View file

@ -175,9 +175,6 @@ class CronTab(object):
self.lines = None self.lines = None
self.ansible = "#Ansible: " self.ansible = "#Ansible: "
# select whether we dump additional debug info through syslog
self.syslogging = False
if cron_file: if cron_file:
self.cron_file = '/etc/cron.d/%s' % cron_file self.cron_file = '/etc/cron.d/%s' % cron_file
else: else:
@ -215,10 +212,6 @@ class CronTab(object):
self.lines.append(l) self.lines.append(l)
count += 1 count += 1
def log_message(self, message):
if self.syslogging:
syslog.syslog(syslog.LOG_NOTICE, 'ansible: "%s"' % message)
def is_empty(self): def is_empty(self):
if len(self.lines) == 0: if len(self.lines) == 0:
return True return True
@ -454,10 +447,8 @@ def main():
# Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option. # Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option.
os.umask(022) os.umask(022)
crontab = CronTab(module, user, cron_file) crontab = CronTab(module, user, cron_file)
]
if crontab.syslogging: module.debug('cron instantiated - name: "%s"' % name)
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'cron instantiated - name: "%s"' % name)
# --- user input validation --- # --- user input validation ---
@ -492,6 +483,7 @@ def main():
(backuph, backup_file) = tempfile.mkstemp(prefix='crontab') (backuph, backup_file) = tempfile.mkstemp(prefix='crontab')
crontab.write(backup_file) crontab.write(backup_file)
if crontab.cron_file and not name and not do_install: if crontab.cron_file and not name and not do_install:
changed = crontab.remove_job_file() changed = crontab.remove_job_file()
module.exit_json(changed=changed,cron_file=cron_file,state=state) module.exit_json(changed=changed,cron_file=cron_file,state=state)

View file

@ -57,7 +57,6 @@ EXAMPLES = '''
''' '''
import grp import grp
import syslog
import platform import platform
class Group(object): class Group(object):
@ -86,13 +85,8 @@ class Group(object):
self.name = module.params['name'] self.name = module.params['name']
self.gid = module.params['gid'] self.gid = module.params['gid']
self.system = module.params['system'] self.system = module.params['system']
self.syslogging = False
def execute_command(self, cmd): def execute_command(self, cmd):
if self.syslogging:
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Command %s' % '|'.join(cmd))
return self.module.run_command(cmd) return self.module.run_command(cmd)
def group_del(self): def group_del(self):
@ -395,11 +389,9 @@ def main():
group = Group(module) group = Group(module)
if group.syslogging: module.debug('Group instantiated - platform %s' % group.platform)
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Group instantiated - platform %s' % group.platform)
if user.distribution: if user.distribution:
syslog.syslog(syslog.LOG_NOTICE, 'Group instantiated - distribution %s' % group.distribution) module.debug('Group instantiated - distribution %s' % group.distribution)
rc = None rc = None
out = '' out = ''

View file

@ -159,9 +159,6 @@ class Service(object):
self.rcconf_value = None self.rcconf_value = None
self.svc_change = False self.svc_change = False
# select whether we dump additional debug info through syslog
self.syslogging = False
# =========================================== # ===========================================
# Platform specific methods (must be replaced by subclass). # Platform specific methods (must be replaced by subclass).
@ -181,9 +178,6 @@ class Service(object):
# Generic methods that should be used on all platforms. # Generic methods that should be used on all platforms.
def execute_command(self, cmd, daemonize=False): def execute_command(self, cmd, daemonize=False):
if self.syslogging:
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Command %s, daemonize %r' % (cmd, daemonize))
# Most things don't need to be daemonized # Most things don't need to be daemonized
if not daemonize: if not daemonize:
@ -1433,11 +1427,9 @@ def main():
service = Service(module) service = Service(module)
if service.syslogging: module.debug('Service instantiated - platform %s' % service.platform)
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Service instantiated - platform %s' % service.platform)
if service.distribution: if service.distribution:
syslog.syslog(syslog.LOG_NOTICE, 'Service instantiated - distribution %s' % service.distribution) module.debug('Service instantiated - distribution %s' % service.distribution)
rc = 0 rc = 0
out = '' out = ''

View file

@ -212,7 +212,6 @@ EXAMPLES = '''
import os import os
import pwd import pwd
import grp import grp
import syslog
import platform import platform
import socket import socket
import time import time
@ -290,15 +289,8 @@ class User(object):
else: else:
self.ssh_file = os.path.join('.ssh', 'id_%s' % self.ssh_type) self.ssh_file = os.path.join('.ssh', 'id_%s' % self.ssh_type)
# select whether we dump additional debug info through syslog
self.syslogging = False
def execute_command(self, cmd, use_unsafe_shell=False, data=None): def execute_command(self, cmd, use_unsafe_shell=False, data=None):
if self.syslogging:
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Command %s' % '|'.join(cmd))
return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data) return self.module.run_command(cmd, use_unsafe_shell=use_unsafe_shell, data=data)
def remove_user_userdel(self): def remove_user_userdel(self):
@ -2079,11 +2071,9 @@ def main():
user = User(module) user = User(module)
if user.syslogging: module.debug('User instantiated - platform %s' % user.platform)
syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'User instantiated - platform %s' % user.platform)
if user.distribution: if user.distribution:
syslog.syslog(syslog.LOG_NOTICE, 'User instantiated - distribution %s' % user.distribution) module.debug('User instantiated - distribution %s' % user.distribution)
rc = None rc = None
out = '' out = ''