I'm trying to insert an output of Linux shell to a variable, but for some reason, the variable always empty.
Here is the Ansible code:
- name: Check PHP version
shell: php -v 2> /dev/null | awk '{print $2; exit}'
register: php_version
- debug: var=php_version
And here is the output:
ok: [10.0.0.5] => {
"php_version": {
"changed": true,
"cmd": "php -v 2> /dev/null | awk '{print $2; exit}'",
"delta": "0:00:00.015180",
"end": "2017-01-08 18:41:00.323773",
"rc": 0,
"start": "2017-01-08 18:41:00.308593",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
When i run the command directly on the server, i get a valid result:
php -v 2> /dev/null | awk '{print $2; exit}'
7.0.14
What could be the issue?
/bin/shthat Ansible uses?2> /dev/null | awk '{print $2; exit}', hopefully you should see the error.