From c95848ae5914a37572f3270beab12e39ba216e8e Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 25 Feb 2013 16:33:04 -0500 Subject: [PATCH 1/3] - add an aliases attribute as a lookup of aliasname to canonical name of parameters - add support for no_log attribute per-parameter which will not log that information to syslog --- lib/ansible/module_common.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 7b3b37af84..d8b560e278 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -161,7 +161,9 @@ class AnsibleModule(object): self.argument_spec = argument_spec self.supports_check_mode = supports_check_mode self.check_mode = False - + + self.aliases = {} + if add_file_common_args: self.argument_spec.update(FILE_COMMON_ARGUMENTS) @@ -169,7 +171,8 @@ class AnsibleModule(object): (self.params, self.args) = self._load_params() self._legal_inputs = [ 'CHECKMODE' ] - self._handle_aliases() + + self.aliases = self._handle_aliases() if check_invalid_arguments: self._check_invalid_arguments() @@ -460,6 +463,7 @@ class AnsibleModule(object): def _handle_aliases(self): + aliases_results = {} #alias:canon for (k,v) in self.argument_spec.iteritems(): self._legal_inputs.append(k) aliases = v.get('aliases', None) @@ -474,8 +478,11 @@ class AnsibleModule(object): self.fail_json(msg='internal error: aliases must be a list') for alias in aliases: self._legal_inputs.append(alias) + aliases_results[alias] = k if alias in self.params: self.params[k] = self.params[alias] + + return aliases_results def _check_for_check_mode(self): for (k,v) in self.params.iteritems(): @@ -583,8 +590,17 @@ class AnsibleModule(object): # Sanitize possible password argument when logging. log_args = dict() passwd_keys = ['password', 'login_password'] + for param in self.params: - if param in passwd_keys: + no_log = False + if self.aliases: + canon = self.aliases.get(param, param) + arg_opts = self.argument_spec[canon] + no_log = arg_opts.get('no_log', False) + + if no_log: + log_args[param] = 'NOT_LOGGING_PARAMETER' + elif param in passwd_keys: log_args[param] = 'NOT_LOGGING_PASSWORD' else: log_args[param] = self.params[param] From b54887b03c5c6b60b3adb442a92c369636b0851f Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 25 Feb 2013 16:34:06 -0500 Subject: [PATCH 2/3] make sure ec2_secret_key is set to no_log=True --- library/ec2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/ec2 b/library/ec2 index 1258d308ec..7d3a141e78 100644 --- a/library/ec2 +++ b/library/ec2 @@ -153,7 +153,7 @@ def main(): ramdisk = dict(), wait = dict(choices=BOOLEANS, default=False), ec2_url = dict(aliases=['EC2_URL']), - ec2_secret_key = dict(aliases=['EC2_SECRET_KEY']), + ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True), ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']), user_data = dict(), instance_tags = dict(), From f02ea15f0c9c2833d139057ae3937cabae1cd6ae Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Mon, 25 Feb 2013 17:07:47 -0500 Subject: [PATCH 3/3] command: make sure that all _handle_aliases() calls returns {} module_common: also work if there are no aliases (shell, command, etc) modules --- lib/ansible/module_common.py | 8 +++----- library/command | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index d8b560e278..24bd14ecbd 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -592,11 +592,9 @@ class AnsibleModule(object): passwd_keys = ['password', 'login_password'] for param in self.params: - no_log = False - if self.aliases: - canon = self.aliases.get(param, param) - arg_opts = self.argument_spec[canon] - no_log = arg_opts.get('no_log', False) + canon = self.aliases.get(param, param) + arg_opts = self.argument_spec.get(canon, {}) + no_log = arg_opts.get('no_log', False) if no_log: log_args[param] = 'NOT_LOGGING_PARAMETER' diff --git a/library/command b/library/command index 13dbb089f6..4e43b9fa3c 100644 --- a/library/command +++ b/library/command @@ -129,7 +129,7 @@ def main(): class CommandModule(AnsibleModule): def _handle_aliases(self): - pass + return {} def _check_invalid_arguments(self): pass