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

**URL:** <https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878>\
**Category:** Ansible Project\
**Created:** [October 31, 2017, 6:12pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878 "2017-10-31T18:12:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 31, 2017, 6:12pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878/1 "2017-10-31T18:12:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 31, 2017, 6:36pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878/2 "2017-10-31T18:36:15Z")

</div>

That is where python has decided the version output should go. It is specifically sent to stderr by the python binary.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 31, 2017, 6:37pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878/3 "2017-10-31T18:37:38Z")

</div>

Also, fwiw, look at the `ansible_python` or `ansible_python_version` variables created during fact gathering, that may be useful to you.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 31, 2017, 7:02pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878/4 "2017-10-31T19:02:14Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 31, 2017, 7:12pm UTC](https://forum.ansible.com/t/command-passes-but-why-is-result-in-stderr-and-not-stdout/25878/5 "2017-10-31T19:12:00Z")

</div>

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?
