Command module bug fix, tests and cleanup. (#30432)

* Add more command integration tests.
* Remove unnecessary command test debug tasks.
* Fix traceback in command module for empty args.
* Remove unreachable code.
pull/30437/head
Matt Clay 7 years ago committed by GitHub
parent f128796782
commit 4ce13e983a

@ -144,7 +144,7 @@ def main():
module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable)
executable = None
if args.strip() == '':
if not args or args.strip() == '':
module.fail_json(rc=256, msg="no command given")
if chdir:
@ -187,11 +187,6 @@ def main():
endd = datetime.datetime.now()
delta = endd - startd
if out is None:
out = b''
if err is None:
err = b''
result = dict(
cmd=args,
stdout=out.rstrip(b"\r\n"),

@ -16,6 +16,69 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: use command to execute sudo
command: sudo -h
register: become
- name: assert become warning was reported
assert:
that:
- "become.warnings | length() == 1"
- "'Consider using' in become.warnings[0]"
- name: use command to execute sudo without warnings
command: sudo -h warn=no
register: become
- name: assert become warning was not reported
assert:
that:
- "'warnings' not in become"
- name: use command to execute tar
command: tar --help
register: tar
- name: assert tar warning was reported
assert:
that:
- "tar.warnings | length() == 1"
- "'Consider using unarchive module rather than running tar' in tar.warnings[0]"
- name: use command to execute chown
command: chown -h
register: chown
ignore_errors: true
- name: assert chown warning was reported
assert:
that:
- "chown.warnings | length() == 1"
- "'Consider using 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
register: executable
- name: assert executable warning was reported
assert:
that:
- "executable.stdout == '/dev/null'"
- "executable.warnings | length() == 1"
- "'no longer supported' in executable.warnings[0]"
- name: use command with no command
command: chdir=/
register: no_command
ignore_errors: true
- name: assert executable fails with no command
assert:
that:
- "no_command.failed == true"
- "no_command.msg == 'no command given'"
- "no_command.rc == 256"
- set_fact: output_dir_test={{output_dir}}/test_command_shell
- name: make sure our testing sub-directory does not exist
@ -143,8 +206,6 @@
this line is the last line
register: command_result6
- debug: var=command_result6
- name: assert the multiline input was passed correctly
assert:
that:
@ -223,8 +284,6 @@
echo "this is a second line"
register: shell_result5
- debug: var=shell_result5
- name: assert the multiline shell command ran as expected
assert:
that:

Loading…
Cancel
Save