{"action":"closed","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/12779","labels_url":"https://api.github.com/repos/ansible/ansible/issues/12779/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/12779/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/12779/events","html_url":"https://github.com/ansible/ansible/issues/12779","id":111830231,"number":12779,"title":"When condition evaluation is ignored for register","user":{"login":"paul-vasiliev","id":743449,"avatar_url":"https://avatars.githubusercontent.com/u/743449?v=3","gravatar_id":"","url":"https://api.github.com/users/paul-vasiliev","html_url":"https://github.com/paul-vasiliev","followers_url":"https://api.github.com/users/paul-vasiliev/followers","following_url":"https://api.github.com/users/paul-vasiliev/following{/other_user}","gists_url":"https://api.github.com/users/paul-vasiliev/gists{/gist_id}","starred_url":"https://api.github.com/users/paul-vasiliev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paul-vasiliev/subscriptions","organizations_url":"https://api.github.com/users/paul-vasiliev/orgs","repos_url":"https://api.github.com/users/paul-vasiliev/repos","events_url":"https://api.github.com/users/paul-vasiliev/events{/privacy}","received_events_url":"https://api.github.com/users/paul-vasiliev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-16T13:19:22Z","updated_at":"2015-10-16T13:33:32Z","closed_at":"2015-10-16T13:33:32Z","body":"##### Issue type: \r\n* Bug Report\r\n\r\n##### Ansible Version: \r\n* 1.9.2\r\n\r\n##### Environment: \r\n* Red Hat Enterprise Linux Server release 7.1 (Maipo) for both control and configured node\r\n\r\n##### Summary:\r\n* **register** is evaluated before **when** when task is ran. This leads to a situation when empty variable is registered even if when condition is false.\r\n\r\n##### Steps To Reproduce:\r\nRun the following playbook:\r\n<pre>\r\n- hosts: \"localhost\"\r\n  tasks:\r\n\r\n    - set_fact: ready_to_rock=\"true\"\r\n\r\n    - name: Simple cmd\r\n      command: ls\r\n      register: download\r\n      when: ready_to_rock\r\n\r\n    - name: Simple cmd\r\n      command: ls\r\n      when: not ready_to_rock\r\n      register: download\r\n\r\n    - debug: msg=\"{{ download }}\"\r\n</pre>\r\n\r\n##### Expected Results:\r\n* **download** variable should contain output of ls command\r\n\r\n##### Actual Results:\r\n* **download** variable is empty\r\n\r\nThere is an old issue #5817 that was opened for the same case, but correct behavior for multiple hosts should be to register a var only for hosts for which when is evaluated to true."}}