{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/20877","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/20877/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/20877/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/20877/events","html_url":"https://github.com/ansible/ansible/issues/20877","id":204374683,"number":20877,"title":"Async task with a poll value >0 shouldn't need async_status to read output","user":{"login":"Harosgr","id":9092383,"avatar_url":"https://avatars.githubusercontent.com/u/9092383?v=3","gravatar_id":"","url":"https://api.github.com/users/Harosgr","html_url":"https://github.com/Harosgr","followers_url":"https://api.github.com/users/Harosgr/followers","following_url":"https://api.github.com/users/Harosgr/following{/other_user}","gists_url":"https://api.github.com/users/Harosgr/gists{/gist_id}","starred_url":"https://api.github.com/users/Harosgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harosgr/subscriptions","organizations_url":"https://api.github.com/users/Harosgr/orgs","repos_url":"https://api.github.com/users/Harosgr/repos","events_url":"https://api.github.com/users/Harosgr/events{/privacy}","received_events_url":"https://api.github.com/users/Harosgr/received_events","type":"User","site_admin":false},"labels":[{"id":454885231,"url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.3","name":"affects_2.3","color":"5319e7","default":false},{"id":48457795,"url":"https://api.github.com/repos/ansible/ansible/labels/feature_idea","name":"feature_idea","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-01-31T18:01:05Z","updated_at":"2017-02-09T15:03:17Z","closed_at":null,"body":"##### ISSUE TYPE\r\n - Feature Idea\r\n\r\n##### COMPONENT NAME\r\nasync\r\n\r\n##### OS / ENVIRONMENT\r\nN/A\r\n\r\n##### SUMMARY\r\nI understand that for a \"fire and forget\" async task with poll: 0, a reasonable way to get the output (stdout, stderr) is by using the async_status, because we need to wait until the task is over.\r\nBut for the case of an async task with poll defined to a value different than zero, why should we need to use the async_status in order to parse the output attributes? The values are already there after the execution of the task.\r\n\r\nAn example would be the following:\r\n\r\n```yaml\r\n- name: run command\r\n  command: python -c 'import os; os.write(2, \"error\")'\r\n  register: output\r\n  async: 500\r\n  poll: 10\r\n  failed_when: \"output.stderr is defined and output.stderr != ''\"\r\n```\r\nThis gives us the following output:\r\n```\r\nchanged: [host] => {\"ansible_job_id\": \"56461191558.12277\", \"changed\": true, \"cmd\": [\"python\", \"-c\", \"import os; os.write(2, \\\"error\\\")\"], \"delta\": \"0:00:00.009468\", \"end\": \"2017-01-31 18:08:13.088458\", \"failed\": false, \"failed_when_result\": false, \"finished\": 1, \"rc\": 0, \"start\": \"2017-01-31 18:08:13.078990\", \"stderr\": \"error\", \"stdout\": \"\", \"stdout_lines\": [], \"warnings\": []}\r\n\r\nPLAY RECAP *********************************************************************\r\nhost : ok=2    changed=1    unreachable=0    failed=0\r\n```\r\nWe see that even though the task is finished and the stderr is set to a string. The failed_when check fails and the playbook returns a succesfull execution.\r\n\r\nIf I use an extra task like this, I can do successfully what I originally wanted\r\n```\r\n- name: Check command\r\n  async_status: jid=\"{{ output.ansible_job_id }}\" \r\n  register: result\r\n  failed_when: \"result.stderr is defined and result.stderr != ''\"\r\n```\r\n\r\nIs there a reason why the attributes cannot be directly accessed when poll > 0? It is not obvious in the documentation that the async_status must be used to parse the output even for the not \"fire and forget\" tasks and to be honest it doesn't make much sense to me. I think it is more straightforward and clean to have direct access to the attributes when poll > 0 than using extra code that might not be needed in the first place.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/278667740","html_url":"https://github.com/ansible/ansible/issues/20877#issuecomment-278667740","issue_url":"https://api.github.com/repos/ansible/ansible/issues/20877","id":278667740,"user":{"login":"nafpliot-ibm","id":19995558,"avatar_url":"https://avatars.githubusercontent.com/u/19995558?v=3","gravatar_id":"","url":"https://api.github.com/users/nafpliot-ibm","html_url":"https://github.com/nafpliot-ibm","followers_url":"https://api.github.com/users/nafpliot-ibm/followers","following_url":"https://api.github.com/users/nafpliot-ibm/following{/other_user}","gists_url":"https://api.github.com/users/nafpliot-ibm/gists{/gist_id}","starred_url":"https://api.github.com/users/nafpliot-ibm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nafpliot-ibm/subscriptions","organizations_url":"https://api.github.com/users/nafpliot-ibm/orgs","repos_url":"https://api.github.com/users/nafpliot-ibm/repos","events_url":"https://api.github.com/users/nafpliot-ibm/events{/privacy}","received_events_url":"https://api.github.com/users/nafpliot-ibm/received_events","type":"User","site_admin":false},"created_at":"2017-02-09T15:03:16Z","updated_at":"2017-02-09T15:03:16Z","body":"Hmm I believe you can close the issue. I think that this strange behavior would be fixed with https://github.com/ansible/ansible/pull/20423"}}
{"actor":{"display_login":"nafpliot-ibm"}}