mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #5843 from jimi-c/issue_4088
Adding no_log: capability for tasks
This commit is contained in:
commit
fcb760c36c
9 changed files with 30 additions and 10 deletions
|
@ -12,6 +12,7 @@ Major features/changes:
|
||||||
* localhost/127.0.0.1 is not required to be in inventory if referenced, if not in inventory, it does not implicitly appear in the 'all' group.
|
* localhost/127.0.0.1 is not required to be in inventory if referenced, if not in inventory, it does not implicitly appear in the 'all' group.
|
||||||
* git module has new parameters (accept_hostkey, key_file, ssh_opts) to ease the usage of git and ssh protocols.
|
* git module has new parameters (accept_hostkey, key_file, ssh_opts) to ease the usage of git and ssh protocols.
|
||||||
* when using accelerate mode, the daemon will now be restarted when specifying a different remote_user between plays.
|
* when using accelerate mode, the daemon will now be restarted when specifying a different remote_user between plays.
|
||||||
|
* added no_log: option for tasks. When used, no logging information will be sent to syslog during the module execution.
|
||||||
|
|
||||||
|
|
||||||
New modules:
|
New modules:
|
||||||
|
|
|
@ -175,6 +175,7 @@ class AnsibleModule(object):
|
||||||
self.argument_spec = argument_spec
|
self.argument_spec = argument_spec
|
||||||
self.supports_check_mode = supports_check_mode
|
self.supports_check_mode = supports_check_mode
|
||||||
self.check_mode = False
|
self.check_mode = False
|
||||||
|
self.no_log = no_log
|
||||||
|
|
||||||
self.aliases = {}
|
self.aliases = {}
|
||||||
|
|
||||||
|
@ -186,13 +187,14 @@ class AnsibleModule(object):
|
||||||
os.environ['LANG'] = MODULE_LANG
|
os.environ['LANG'] = MODULE_LANG
|
||||||
(self.params, self.args) = self._load_params()
|
(self.params, self.args) = self._load_params()
|
||||||
|
|
||||||
self._legal_inputs = [ 'CHECKMODE' ]
|
self._legal_inputs = [ 'CHECKMODE', 'NO_LOG' ]
|
||||||
|
|
||||||
self.aliases = self._handle_aliases()
|
self.aliases = self._handle_aliases()
|
||||||
|
|
||||||
if check_invalid_arguments:
|
if check_invalid_arguments:
|
||||||
self._check_invalid_arguments()
|
self._check_invalid_arguments()
|
||||||
self._check_for_check_mode()
|
self._check_for_check_mode()
|
||||||
|
self._check_for_no_log()
|
||||||
|
|
||||||
self._set_defaults(pre=True)
|
self._set_defaults(pre=True)
|
||||||
|
|
||||||
|
@ -205,7 +207,7 @@ class AnsibleModule(object):
|
||||||
self._check_required_one_of(required_one_of)
|
self._check_required_one_of(required_one_of)
|
||||||
|
|
||||||
self._set_defaults(pre=False)
|
self._set_defaults(pre=False)
|
||||||
if not no_log:
|
if not self.no_log:
|
||||||
self._log_invocation()
|
self._log_invocation()
|
||||||
|
|
||||||
def load_file_common_arguments(self, params):
|
def load_file_common_arguments(self, params):
|
||||||
|
@ -558,9 +560,14 @@ class AnsibleModule(object):
|
||||||
if self.supports_check_mode:
|
if self.supports_check_mode:
|
||||||
self.check_mode = True
|
self.check_mode = True
|
||||||
|
|
||||||
|
def _check_for_no_log(self):
|
||||||
|
for (k,v) in self.params.iteritems():
|
||||||
|
if k == 'NO_LOG':
|
||||||
|
self.no_log = self.boolean(v)
|
||||||
|
|
||||||
def _check_invalid_arguments(self):
|
def _check_invalid_arguments(self):
|
||||||
for (k,v) in self.params.iteritems():
|
for (k,v) in self.params.iteritems():
|
||||||
if k == 'CHECKMODE':
|
if k in ('CHECKMODE', 'NO_LOG'):
|
||||||
continue
|
continue
|
||||||
if k not in self._legal_inputs:
|
if k not in self._legal_inputs:
|
||||||
self.fail_json(msg="unsupported parameter for module: %s" % k)
|
self.fail_json(msg="unsupported parameter for module: %s" % k)
|
||||||
|
|
|
@ -343,7 +343,8 @@ class PlayBook(object):
|
||||||
su=task.su,
|
su=task.su,
|
||||||
su_user=task.su_user,
|
su_user=task.su_user,
|
||||||
su_pass=task.su_pass,
|
su_pass=task.su_pass,
|
||||||
run_hosts=hosts
|
run_hosts=hosts,
|
||||||
|
no_log=task.no_log,
|
||||||
)
|
)
|
||||||
|
|
||||||
if task.async_seconds == 0:
|
if task.async_seconds == 0:
|
||||||
|
|
|
@ -504,7 +504,7 @@ class Play(object):
|
||||||
elif type(x[k]) is list:
|
elif type(x[k]) is list:
|
||||||
for i in x[k]:
|
for i in x[k]:
|
||||||
included_additional_conditions.insert(0, i)
|
included_additional_conditions.insert(0, i)
|
||||||
elif k in ("include", "vars", "default_vars", "sudo", "sudo_user", "role_name"):
|
elif k in ("include", "vars", "default_vars", "sudo", "sudo_user", "role_name", "no_log"):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
include_vars[k] = x[k]
|
include_vars[k] = x[k]
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Task(object):
|
||||||
'local_action', 'transport', 'sudo', 'remote_user', 'sudo_user', 'sudo_pass',
|
'local_action', 'transport', 'sudo', 'remote_user', 'sudo_user', 'sudo_pass',
|
||||||
'items_lookup_plugin', 'items_lookup_terms', 'environment', 'args',
|
'items_lookup_plugin', 'items_lookup_terms', 'environment', 'args',
|
||||||
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run', 'delay', 'retries', 'until',
|
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run', 'delay', 'retries', 'until',
|
||||||
'su', 'su_user', 'su_pass'
|
'su', 'su_user', 'su_pass', 'no_log',
|
||||||
]
|
]
|
||||||
|
|
||||||
# to prevent typos and such
|
# to prevent typos and such
|
||||||
|
@ -41,7 +41,7 @@ class Task(object):
|
||||||
'delegate_to', 'local_action', 'transport', 'remote_user', 'sudo', 'sudo_user',
|
'delegate_to', 'local_action', 'transport', 'remote_user', 'sudo', 'sudo_user',
|
||||||
'sudo_pass', 'when', 'connection', 'environment', 'args',
|
'sudo_pass', 'when', 'connection', 'environment', 'args',
|
||||||
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run', 'delay', 'retries', 'until',
|
'any_errors_fatal', 'changed_when', 'failed_when', 'always_run', 'delay', 'retries', 'until',
|
||||||
'su', 'su_user', 'su_pass'
|
'su', 'su_user', 'su_pass', 'no_log',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, play, ds, module_vars=None, default_vars=None, additional_conditions=None, role_name=None):
|
def __init__(self, play, ds, module_vars=None, default_vars=None, additional_conditions=None, role_name=None):
|
||||||
|
@ -106,7 +106,6 @@ class Task(object):
|
||||||
when_name = x.replace("when_","")
|
when_name = x.replace("when_","")
|
||||||
ds['when'] = "%s %s" % (when_name, ds[x])
|
ds['when'] = "%s %s" % (when_name, ds[x])
|
||||||
ds.pop(x)
|
ds.pop(x)
|
||||||
|
|
||||||
elif not x in Task.VALID_KEYS:
|
elif not x in Task.VALID_KEYS:
|
||||||
raise errors.AnsibleError("%s is not a legal parameter in an Ansible task or handler" % x)
|
raise errors.AnsibleError("%s is not a legal parameter in an Ansible task or handler" % x)
|
||||||
|
|
||||||
|
@ -122,7 +121,8 @@ class Task(object):
|
||||||
self.su = utils.boolean(ds.get('su', play.su))
|
self.su = utils.boolean(ds.get('su', play.su))
|
||||||
self.environment = ds.get('environment', {})
|
self.environment = ds.get('environment', {})
|
||||||
self.role_name = role_name
|
self.role_name = role_name
|
||||||
|
self.no_log = utils.boolean(ds.get('no_log', "false"))
|
||||||
|
|
||||||
#Code to allow do until feature in a Task
|
#Code to allow do until feature in a Task
|
||||||
if 'until' in ds:
|
if 'until' in ds:
|
||||||
if not ds.get('register'):
|
if not ds.get('register'):
|
||||||
|
|
|
@ -145,6 +145,7 @@ class Runner(object):
|
||||||
su_user=None, # User to su to when running command, ex: 'root'
|
su_user=None, # User to su to when running command, ex: 'root'
|
||||||
su_pass=C.DEFAULT_SU_PASS,
|
su_pass=C.DEFAULT_SU_PASS,
|
||||||
run_hosts=None, # an optional list of pre-calculated hosts to run on
|
run_hosts=None, # an optional list of pre-calculated hosts to run on
|
||||||
|
no_log=False, # option to enable/disable logging for a given task
|
||||||
):
|
):
|
||||||
|
|
||||||
# used to lock multiprocess inputs and outputs at various levels
|
# used to lock multiprocess inputs and outputs at various levels
|
||||||
|
@ -196,6 +197,7 @@ class Runner(object):
|
||||||
self.su_user_var = su_user
|
self.su_user_var = su_user
|
||||||
self.su_user = None
|
self.su_user = None
|
||||||
self.su_pass = su_pass
|
self.su_pass = su_pass
|
||||||
|
self.no_log = no_log
|
||||||
|
|
||||||
if self.transport == 'smart':
|
if self.transport == 'smart':
|
||||||
# if the transport is 'smart' see if SSH can support ControlPersist if not use paramiko
|
# if the transport is 'smart' see if SSH can support ControlPersist if not use paramiko
|
||||||
|
@ -341,6 +343,8 @@ class Runner(object):
|
||||||
# if module isn't using AnsibleModuleCommon infrastructure we can't be certain it knows how to
|
# if module isn't using AnsibleModuleCommon infrastructure we can't be certain it knows how to
|
||||||
# do --check mode, so to be safe we will not run it.
|
# do --check mode, so to be safe we will not run it.
|
||||||
return ReturnData(conn=conn, result=dict(skipped=True, msg="cannot yet run check mode against old-style modules"))
|
return ReturnData(conn=conn, result=dict(skipped=True, msg="cannot yet run check mode against old-style modules"))
|
||||||
|
elif 'NO_LOG' in args:
|
||||||
|
return ReturnData(conn=conn, result=dict(skipped=True, msg="cannot use no_log: with old-style modules"))
|
||||||
|
|
||||||
args = template.template(self.basedir, args, inject)
|
args = template.template(self.basedir, args, inject)
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,8 @@ class ActionModule(object):
|
||||||
pipes.quote(tmp_src), pipes.quote(source_rel))
|
pipes.quote(tmp_src), pipes.quote(source_rel))
|
||||||
if self.runner.noop_on_check(inject):
|
if self.runner.noop_on_check(inject):
|
||||||
module_args_tmp = "%s CHECKMODE=True" % module_args_tmp
|
module_args_tmp = "%s CHECKMODE=True" % module_args_tmp
|
||||||
|
if self.runner.no_log:
|
||||||
|
module_args_tmp = "%s NO_LOG=True" % module_args_tmp
|
||||||
module_return = self.runner._execute_module(conn, tmp, 'file', module_args_tmp, inject=inject, complex_args=complex_args)
|
module_return = self.runner._execute_module(conn, tmp, 'file', module_args_tmp, inject=inject, complex_args=complex_args)
|
||||||
|
|
||||||
module_result = module_return.result
|
module_result = module_return.result
|
||||||
|
|
|
@ -45,6 +45,9 @@ class ActionModule(object):
|
||||||
# python modules for now
|
# python modules for now
|
||||||
module_args += " CHECKMODE=True"
|
module_args += " CHECKMODE=True"
|
||||||
|
|
||||||
|
if self.runner.no_log:
|
||||||
|
module_args += " NO_LOG=True"
|
||||||
|
|
||||||
# shell and command are the same module
|
# shell and command are the same module
|
||||||
if module_name == 'shell':
|
if module_name == 'shell':
|
||||||
module_name = 'command'
|
module_name = 'command'
|
||||||
|
|
|
@ -184,7 +184,7 @@ class CommandModule(AnsibleModule):
|
||||||
args = args.replace("#USE_SHELL", "")
|
args = args.replace("#USE_SHELL", "")
|
||||||
params['shell'] = True
|
params['shell'] = True
|
||||||
|
|
||||||
r = re.compile(r'(^|\s)(creates|removes|chdir|executable)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)')
|
r = re.compile(r'(^|\s)(creates|removes|chdir|executable|NO_LOG)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)')
|
||||||
for m in r.finditer(args):
|
for m in r.finditer(args):
|
||||||
v = m.group(4).replace("\\", "")
|
v = m.group(4).replace("\\", "")
|
||||||
if m.group(2) == "creates":
|
if m.group(2) == "creates":
|
||||||
|
@ -203,6 +203,8 @@ class CommandModule(AnsibleModule):
|
||||||
if not (os.path.exists(v)):
|
if not (os.path.exists(v)):
|
||||||
self.fail_json(rc=258, msg="cannot use executable '%s': file does not exist" % v)
|
self.fail_json(rc=258, msg="cannot use executable '%s': file does not exist" % v)
|
||||||
params['executable'] = v
|
params['executable'] = v
|
||||||
|
elif m.group(2) == "NO_LOG":
|
||||||
|
params['NO_LOG'] = self.boolean(v)
|
||||||
args = r.sub("", args)
|
args = r.sub("", args)
|
||||||
params['args'] = args
|
params['args'] = args
|
||||||
return (params, params['args'])
|
return (params, params['args'])
|
||||||
|
|
Loading…
Reference in a new issue