I am trying to insert Linux shell output into a variable, but for some reason the variable is 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 conclusion:
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 the correct result:
php -v 2> /dev/null | awk '{print $2; exit}'
7.0.14
What could be the problem?
source
share