Command passes, but why is result in stderr and not stdout?

18 views
Skip to first unread message

ZillaYT

unread,
Oct 31, 2017, 2:12:56 PM10/31/17
to Ansible Project
I have the following simple task to check my Python version

- name: Check if Python version matches target
  commadn: "/local/python/bin/python --version"
  register: python_ver_check

- debug: var=python_ver_check

and I get

TASK [python3 : debug] *********************************************************
ok: [localhost] => {
    "python_ver_check": {
        "changed": true,
        "cmd": "/local/python/bin/python --version",
        "delta": "0:00:00.003369",
        "end": "2017-10-31 14:00:10.701899",
        "failed": false,
        "rc": 0,
        "start": "2017-10-31 14:00:10.698530",
        "stderr": "Python 2.7.14",
        "stderr_lines": [
            "Python 2.7.14"
        ],
        "stdout": "",
        "stdout_lines": []
    }
}


Why stderr and not stdout? The task executed with no errors.

Matt Martz

unread,
Oct 31, 2017, 2:37:09 PM10/31/17
to ansible...@googlegroups.com
That is where python has decided the version output should go.  It is specifically sent to stderr by the python binary.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6a719713-75ce-4cba-9d89-8acafbfd6323%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Matt Martz

unread,
Oct 31, 2017, 2:38:35 PM10/31/17
to ansible...@googlegroups.com
Also, fwiw, look at the `ansible_python` or `ansible_python_version` variables created during fact gathering, that may be useful to you.

ZillaYT

unread,
Oct 31, 2017, 3:02:14 PM10/31/17
to Ansible Project
Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
--
Matt Martz
@sivel
sivel.net

ZillaYT

unread,
Oct 31, 2017, 3:12:00 PM10/31/17
to Ansible Project
How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via "ansible --version" command that it's using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?


On Tuesday, October 31, 2017 at 2:38:35 PM UTC-4, Matt Martz wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages