From d4069a8a8ad9825aeb5acb2a3c77fdab9644da90 Mon Sep 17 00:00:00 2001 From: Bill Nottingham Date: Mon, 27 Jul 2015 11:02:24 -0400 Subject: [PATCH] Warn on use of sudo, etc. in shell/command. --- lib/ansible/modules/commands/command.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/modules/commands/command.py b/lib/ansible/modules/commands/command.py index dbb23949273..b703c669b68 100644 --- a/lib/ansible/modules/commands/command.py +++ b/lib/ansible/modules/commands/command.py @@ -144,12 +144,15 @@ def check_command(commandline): 'mount': 'mount', 'rpm': 'yum', 'yum': 'yum', 'apt-get': 'apt-get', 'tar': 'unarchive', 'unzip': 'unarchive', 'sed': 'template or lineinfile', 'rsync': 'synchronize' } + become = [ 'sudo', 'su', 'pbrun', 'pfexec', 'runas' ] warnings = list() command = os.path.basename(commandline.split()[0]) if command in arguments: warnings.append("Consider using file module with %s rather than running %s" % (arguments[command], command)) if command in commands: warnings.append("Consider using %s module rather than running %s" % (commands[command], command)) + if command in become: + warnings.append("Consider using 'become', 'become_method', and 'become_user' rather than running %s" % (command,)) return warnings