Have command nanny tell you how to disable the warning (#34061)
* Have command nanny tell you how to disable the warning
This commit is contained in:
parent
790c06c079
commit
2e1c889275
2 changed files with 17 additions and 4 deletions
|
@ -132,10 +132,23 @@ def check_command(module, commandline):
|
|||
'dnf': 'dnf', 'zypper': 'zypper'}
|
||||
become = ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'pmrun']
|
||||
command = os.path.basename(commandline.split()[0])
|
||||
|
||||
disable_suffix = "If you need to use command because {mod} is insufficient you can add" \
|
||||
" warn=False to this command task or set command_warnings=False in" \
|
||||
" ansible.cfg to get rid of this message."
|
||||
substitutions = {'mod': None, 'cmd': command}
|
||||
|
||||
if command in arguments:
|
||||
module.warn("Consider using file module with %s rather than running %s" % (arguments[command], command))
|
||||
msg = "Consider using the {mod} module with {subcmd} rather than running {cmd}. " + disable_suffix
|
||||
substitutions['mod'] = 'file'
|
||||
substitutions['subcmd'] = arguments[command]
|
||||
module.warn(msg.format(**substitutions))
|
||||
|
||||
if command in commands:
|
||||
module.warn("Consider using %s module rather than running %s" % (commands[command], command))
|
||||
msg = "Consider using the {mod} module rather than running {cmd}. " + disable_suffix
|
||||
substitutions['mod'] = commands[command]
|
||||
module.warn(msg.format(**substitutions))
|
||||
|
||||
if command in become:
|
||||
module.warn("Consider using 'become', 'become_method', and 'become_user' rather than running %s" % (command,))
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
assert:
|
||||
that:
|
||||
- "tar.warnings | length() == 1"
|
||||
- "'Consider using unarchive module rather than running tar' in tar.warnings[0]"
|
||||
- "'Consider using the unarchive module rather than running tar' in tar.warnings[0]"
|
||||
|
||||
- name: use command to execute chown
|
||||
command: chown -h
|
||||
|
@ -54,7 +54,7 @@
|
|||
assert:
|
||||
that:
|
||||
- "chown.warnings | length() == 1"
|
||||
- "'Consider using file module with owner rather than running chown' in chown.warnings[0]"
|
||||
- "'Consider using the file module with owner rather than running chown' in chown.warnings[0]"
|
||||
|
||||
- name: use command with unsupported executable arg
|
||||
command: ls /dev/null executable=/bogus
|
||||
|
|
Loading…
Reference in a new issue