检查python版本通过导致错误的结果

您好我正在检查使用可靠的任务python的版本但是我得到的输出值在stderrvariables而不是标准输出。

这是我的任务检查pthon版本。

--- - shell: "python --version" register: python_installed 

这是任务的输出:

 changed: [172.17.0.3] => { "changed": true, "cmd": "python --version", "delta": "0:00:00.259578", "end": "2017-06-30 03:43:44.341772", "invocation": { "module_args": { "_raw_params": "python --version", "_uses_shell": true, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true } }, "rc": 0, "start": "2017-06-30 03:43:44.082194", "stderr": "Python 2.6.6", "stderr_lines": [ "Python 2.6.6" ], "stdout": "", "stdout_lines": [] 

}

我试图在可执行文件中添加pythonpath,但也失败了。 我也试过使用shell模块的命令模块。 仍然失败

我看到这里没有错误。 命令已成功执行( rc=0 )。

Python的-v开关应该写入stderr的版本号。 来源 :

 fprintf(stderr, "Python %s\n", PY_VERSION); 

如果(出于某种原因)你需要在stdout中看到它,请使用描述符redirect:

 - shell: python --version 2>&1 

正如一个注释:

Python版本已经由setup_module收集,可以通过ansible_python_version访问

 ansible -m setup localhost | grep ansible_python_version "ansible_python_version": "3.6.1",