mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
switched to use module loggigng
This commit is contained in:
parent
a04972c79b
commit
ae84177514
5 changed files with 16 additions and 48 deletions
|
@ -379,7 +379,6 @@ tenant_ip: "192.168.200.21/23"
|
||||||
'''
|
'''
|
||||||
# import ansible.module_utils.basic
|
# import ansible.module_utils.basic
|
||||||
import os
|
import os
|
||||||
import syslog
|
|
||||||
import sys
|
import sys
|
||||||
import dbus
|
import dbus
|
||||||
from gi.repository import NetworkManager, NMClient
|
from gi.repository import NetworkManager, NMClient
|
||||||
|
@ -466,14 +465,8 @@ class Nmcli(object):
|
||||||
self.flags=module.params['flags']
|
self.flags=module.params['flags']
|
||||||
self.ingress=module.params['ingress']
|
self.ingress=module.params['ingress']
|
||||||
self.egress=module.params['egress']
|
self.egress=module.params['egress']
|
||||||
# select whether we dump additional debug info through syslog
|
|
||||||
self.syslogging=True
|
|
||||||
|
|
||||||
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 merge_secrets(self, proxy, config, setting_name):
|
def merge_secrets(self, proxy, config, setting_name):
|
||||||
|
|
|
@ -167,9 +167,7 @@ class OVSBridge(object):
|
||||||
|
|
||||||
current_fail_mode = self.get_fail_mode()
|
current_fail_mode = self.get_fail_mode()
|
||||||
if self.fail_mode and (self.fail_mode != current_fail_mode):
|
if self.fail_mode and (self.fail_mode != current_fail_mode):
|
||||||
syslog.syslog(syslog.LOG_NOTICE,
|
self.module.log( "changing fail mode %s to %s" % (current_fail_mode, self.fail_mode))
|
||||||
"changing fail mode %s to %s" %
|
|
||||||
(current_fail_mode, self.fail_mode))
|
|
||||||
self.set_fail_mode()
|
self.set_fail_mode()
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import syslog
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: openvswitch_port
|
module: openvswitch_port
|
||||||
|
@ -99,7 +97,7 @@ def truncate_before(value, srch):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def _set_to_get(set_cmd):
|
def _set_to_get(set_cmd, module):
|
||||||
""" Convert set command to get command and set value.
|
""" Convert set command to get command and set value.
|
||||||
return tuple (get command, set value)
|
return tuple (get command, set value)
|
||||||
"""
|
"""
|
||||||
|
@ -109,7 +107,7 @@ def _set_to_get(set_cmd):
|
||||||
set_cmd = truncate_before(set_cmd, " option:")
|
set_cmd = truncate_before(set_cmd, " option:")
|
||||||
get_cmd = set_cmd.split(" ")
|
get_cmd = set_cmd.split(" ")
|
||||||
(key, value) = get_cmd[-1].split("=")
|
(key, value) = get_cmd[-1].split("=")
|
||||||
syslog.syslog(syslog.LOG_NOTICE, "get commands %s " % key)
|
module.log("get commands %s " % key)
|
||||||
return (["--", "get"] + get_cmd[:-1] + [key], value)
|
return (["--", "get"] + get_cmd[:-1] + [key], value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +126,6 @@ class OVSPort(object):
|
||||||
'''Run ovs-vsctl command'''
|
'''Run ovs-vsctl command'''
|
||||||
|
|
||||||
cmd = ['ovs-vsctl', '-t', str(self.timeout)] + command
|
cmd = ['ovs-vsctl', '-t', str(self.timeout)] + command
|
||||||
syslog.syslog(syslog.LOG_NOTICE, " ".join(cmd))
|
|
||||||
return self.module.run_command(cmd, check_rc=check_rc)
|
return self.module.run_command(cmd, check_rc=check_rc)
|
||||||
|
|
||||||
def exists(self):
|
def exists(self):
|
||||||
|
@ -143,11 +140,11 @@ class OVSPort(object):
|
||||||
|
|
||||||
def set(self, set_opt):
|
def set(self, set_opt):
|
||||||
""" Set attributes on a port. """
|
""" Set attributes on a port. """
|
||||||
syslog.syslog(syslog.LOG_NOTICE, "set called %s" % set_opt)
|
self.module("set called %s" % set_opt)
|
||||||
if (not set_opt):
|
if (not set_opt):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
(get_cmd, set_value) = _set_to_get(set_opt)
|
(get_cmd, set_value) = _set_to_get(set_opt, self.module)
|
||||||
(rtc, out, err) = self._vsctl(get_cmd, False)
|
(rtc, out, err) = self._vsctl(get_cmd, False)
|
||||||
if rtc != 0:
|
if rtc != 0:
|
||||||
##
|
##
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import syslog
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -64,13 +63,8 @@ EXAMPLES = '''
|
||||||
- openbsd_pkg: name=* state=latest
|
- openbsd_pkg: name=* state=latest
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Control if we write debug information to syslog.
|
|
||||||
debug = False
|
|
||||||
|
|
||||||
# Function used for executing commands.
|
# Function used for executing commands.
|
||||||
def execute_command(cmd, module):
|
def execute_command(cmd, module):
|
||||||
if debug:
|
|
||||||
syslog.syslog("execute_command(): cmd = %s" % cmd)
|
|
||||||
# Break command line into arguments.
|
# Break command line into arguments.
|
||||||
# This makes run_command() use shell=False which we need to not cause shell
|
# This makes run_command() use shell=False which we need to not cause shell
|
||||||
# expansion of special characters like '*'.
|
# expansion of special characters like '*'.
|
||||||
|
@ -91,12 +85,10 @@ def get_current_name(name, pkg_spec, module):
|
||||||
else:
|
else:
|
||||||
pattern = "^%s-" % pkg_spec['stem']
|
pattern = "^%s-" % pkg_spec['stem']
|
||||||
|
|
||||||
if debug:
|
module.debug("get_current_name(): pattern = %s" % pattern)
|
||||||
syslog.syslog("get_current_name(): pattern = %s" % pattern)
|
|
||||||
|
|
||||||
for line in stdout.splitlines():
|
for line in stdout.splitlines():
|
||||||
if debug:
|
module.debug("get_current_name: line = %s" % line)
|
||||||
syslog.syslog("get_current_name: line = %s" % line)
|
|
||||||
match = re.search(pattern, line)
|
match = re.search(pattern, line)
|
||||||
if match:
|
if match:
|
||||||
current_name = line.split()[0]
|
current_name = line.split()[0]
|
||||||
|
@ -144,14 +136,12 @@ def package_present(name, installed_state, pkg_spec, module):
|
||||||
# supplied the tool will exit 0 in both cases:
|
# supplied the tool will exit 0 in both cases:
|
||||||
if pkg_spec['version']:
|
if pkg_spec['version']:
|
||||||
# Depend on the return code.
|
# Depend on the return code.
|
||||||
if debug:
|
module.debug("package_present(): depending on return code")
|
||||||
syslog.syslog("package_present(): depending on return code")
|
|
||||||
if rc:
|
if rc:
|
||||||
changed=False
|
changed=False
|
||||||
else:
|
else:
|
||||||
# Depend on stderr instead.
|
# Depend on stderr instead.
|
||||||
if debug:
|
module.debug("package_present(): depending on stderr")
|
||||||
syslog.syslog("package_present(): depending on stderr")
|
|
||||||
if stderr:
|
if stderr:
|
||||||
# There is a corner case where having an empty directory in
|
# There is a corner case where having an empty directory in
|
||||||
# installpath prior to the right location will result in a
|
# installpath prior to the right location will result in a
|
||||||
|
@ -161,18 +151,15 @@ def package_present(name, installed_state, pkg_spec, module):
|
||||||
match = re.search("\W%s-[^:]+: ok\W" % name, stdout)
|
match = re.search("\W%s-[^:]+: ok\W" % name, stdout)
|
||||||
if match:
|
if match:
|
||||||
# It turns out we were able to install the package.
|
# It turns out we were able to install the package.
|
||||||
if debug:
|
module.debug("package_present(): we were able to install package")
|
||||||
syslog.syslog("package_present(): we were able to install package")
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# We really did fail, fake the return code.
|
# We really did fail, fake the return code.
|
||||||
if debug:
|
module.debug("package_present(): we really did fail")
|
||||||
syslog.syslog("package_present(): we really did fail")
|
|
||||||
rc = 1
|
rc = 1
|
||||||
changed=False
|
changed=False
|
||||||
else:
|
else:
|
||||||
if debug:
|
module.debug("package_present(): stderr was not set")
|
||||||
syslog.syslog("package_present(): stderr was not set")
|
|
||||||
|
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
|
@ -202,8 +189,7 @@ def package_latest(name, installed_state, pkg_spec, module):
|
||||||
# Fetch name of currently installed package.
|
# Fetch name of currently installed package.
|
||||||
pre_upgrade_name = get_current_name(name, pkg_spec, module)
|
pre_upgrade_name = get_current_name(name, pkg_spec, module)
|
||||||
|
|
||||||
if debug:
|
module.debug("package_latest(): pre_upgrade_name = %s" % pre_upgrade_name)
|
||||||
syslog.syslog("package_latest(): pre_upgrade_name = %s" % pre_upgrade_name)
|
|
||||||
|
|
||||||
# Attempt to upgrade the package.
|
# Attempt to upgrade the package.
|
||||||
(rc, stdout, stderr) = execute_command("%s %s" % (upgrade_cmd, name), module)
|
(rc, stdout, stderr) = execute_command("%s %s" % (upgrade_cmd, name), module)
|
||||||
|
@ -237,8 +223,7 @@ def package_latest(name, installed_state, pkg_spec, module):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If package was not installed at all just make it present.
|
# If package was not installed at all just make it present.
|
||||||
if debug:
|
module.debug("package_latest(): package is not installed, calling package_present()")
|
||||||
syslog.syslog("package_latest(): package is not installed, calling package_present()")
|
|
||||||
return package_present(name, installed_state, pkg_spec, module)
|
return package_present(name, installed_state, pkg_spec, module)
|
||||||
|
|
||||||
# Function used to make sure a package is not installed.
|
# Function used to make sure a package is not installed.
|
||||||
|
|
|
@ -124,8 +124,6 @@ class CronVar(object):
|
||||||
self.user = 'root'
|
self.user = 'root'
|
||||||
self.lines = None
|
self.lines = None
|
||||||
self.wordchars = ''.join(chr(x) for x in range(128) if chr(x) not in ('=', "'", '"', ))
|
self.wordchars = ''.join(chr(x) for x in range(128) if chr(x) not in ('=', "'", '"', ))
|
||||||
# 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
|
||||||
|
@ -165,8 +163,7 @@ class CronVar(object):
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
def log_message(self, message):
|
def log_message(self, message):
|
||||||
if self.syslogging:
|
self.module.debug('ansible: "%s"' % message)
|
||||||
syslog.syslog(syslog.LOG_NOTICE, 'ansible: "%s"' % message)
|
|
||||||
|
|
||||||
def write(self, backup_file=None):
|
def write(self, backup_file=None):
|
||||||
"""
|
"""
|
||||||
|
@ -363,9 +360,7 @@ def main():
|
||||||
os.umask(022)
|
os.umask(022)
|
||||||
cronvar = CronVar(module, user, cron_file)
|
cronvar = CronVar(module, user, cron_file)
|
||||||
|
|
||||||
if cronvar.syslogging:
|
module.debug('cronvar instantiated - name: "%s"' % name)
|
||||||
syslog.openlog('ansible-%s' % os.path.basename(__file__))
|
|
||||||
syslog.syslog(syslog.LOG_NOTICE, 'cronvar instantiated - name: "%s"' % name)
|
|
||||||
|
|
||||||
# --- user input validation ---
|
# --- user input validation ---
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue