{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/15963","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/15963/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/15963/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/15963/events","html_url":"https://github.com/ansible/ansible/issues/15963","id":156234610,"number":15963,"title":"Error in included task in block level does not trigger always section ","user":{"login":"betrcode","id":777108,"avatar_url":"https://avatars.githubusercontent.com/u/777108?v=3","gravatar_id":"","url":"https://api.github.com/users/betrcode","html_url":"https://github.com/betrcode","followers_url":"https://api.github.com/users/betrcode/followers","following_url":"https://api.github.com/users/betrcode/following{/other_user}","gists_url":"https://api.github.com/users/betrcode/gists{/gist_id}","starred_url":"https://api.github.com/users/betrcode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betrcode/subscriptions","organizations_url":"https://api.github.com/users/betrcode/orgs","repos_url":"https://api.github.com/users/betrcode/repos","events_url":"https://api.github.com/users/betrcode/events{/privacy}","received_events_url":"https://api.github.com/users/betrcode/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.0","name":"affects_2.0","color":"5319e7"},{"url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.1","name":"affects_2.1","color":"5319e7"},{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"jimi-c","id":26403,"avatar_url":"https://avatars.githubusercontent.com/u/26403?v=3","gravatar_id":"","url":"https://api.github.com/users/jimi-c","html_url":"https://github.com/jimi-c","followers_url":"https://api.github.com/users/jimi-c/followers","following_url":"https://api.github.com/users/jimi-c/following{/other_user}","gists_url":"https://api.github.com/users/jimi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/jimi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimi-c/subscriptions","organizations_url":"https://api.github.com/users/jimi-c/orgs","repos_url":"https://api.github.com/users/jimi-c/repos","events_url":"https://api.github.com/users/jimi-c/events{/privacy}","received_events_url":"https://api.github.com/users/jimi-c/received_events","type":"User","site_admin":false},"assignees":[{"login":"jimi-c","id":26403,"avatar_url":"https://avatars.githubusercontent.com/u/26403?v=3","gravatar_id":"","url":"https://api.github.com/users/jimi-c","html_url":"https://github.com/jimi-c","followers_url":"https://api.github.com/users/jimi-c/followers","following_url":"https://api.github.com/users/jimi-c/following{/other_user}","gists_url":"https://api.github.com/users/jimi-c/gists{/gist_id}","starred_url":"https://api.github.com/users/jimi-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimi-c/subscriptions","organizations_url":"https://api.github.com/users/jimi-c/orgs","repos_url":"https://api.github.com/users/jimi-c/repos","events_url":"https://api.github.com/users/jimi-c/events{/privacy}","received_events_url":"https://api.github.com/users/jimi-c/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2016-05-23T09:16:48Z","updated_at":"2016-09-15T15:48:56Z","closed_at":null,"body":"Can't find this reported anywhere.\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.0.1.0\r\n```\r\n\r\n##### CONFIGURATION\r\n* No settings in ansible.cfg \r\n* Not using ANSIBLE_* environment variables\r\n\r\n##### OS / ENVIRONMENT\r\n* Running from Ubuntu 12.04\r\n* Managing CentOS 7\r\n\r\n##### SUMMARY\r\nTrying to use \"- block:\" with \"always:\" section to always put an instance back into a load balancer even when some task in the playbook has failed.\r\n\r\nThis seems to work only when tasks are inlined in the playbook, but not when they are included from another file.\r\n\r\n##### STEPS TO REPRODUCE\r\nCreate `test-fail.yml` with contents:\r\n```\r\n- command: /bin/false\r\n```\r\nCreate the `block-test.yml` playbook with contents:\r\n```\r\n---\r\n\r\n- hosts: localhost\r\n\r\n  tasks:\r\n    - block:\r\n      - debug: msg='i execute normally'\r\n      - include: test-fail.yml\r\n      - debug: msg='i never execute, cause ERROR!'\r\n      always:\r\n      - debug: msg='in always section'\r\n```\r\n\r\nRun the playbook:\r\n`ansible-playbook block-test.yml`\r\n\r\n##### EXPECTED RESULTS\r\nThe \"in always section\" message should be printed on screen.\r\n\r\n##### ACTUAL RESULTS\r\nActual result:\r\n```\r\n [WARNING]: provided hosts list is empty, only localhost is available\r\n\r\nLoaded callback default of type stdout, v2.0\r\n1 plays in block-test.yml\r\n\r\nPLAY ***************************************************************************\r\n\r\nTASK [setup] *******************************************************************\r\nESTABLISH LOCAL CONNECTION FOR USER: max\r\n127.0.0.1 EXEC /bin/sh -c '( umask 22 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1463994869.68-81529732628427 `\" && echo \"` echo $HOME/.ansible/tmp/ansible-tmp-1463994869.68-81529732628427 `\" )'\r\n127.0.0.1 PUT /tmp/tmpwg3sKD TO /home/max/.ansible/tmp/ansible-tmp-1463994869.68-81529732628427/setup\r\n127.0.0.1 EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/max/.ansible/tmp/ansible-tmp-1463994869.68-81529732628427/setup; rm -rf \"/home/max/.ansible/tmp/ansible-tmp-1463994869.68-81529732628427/\" > /dev/null 2>&1'\r\nok: [localhost]\r\n\r\nTASK [debug] *******************************************************************\r\ntask path: /home/max/repos/lookup-ansible/block-test.yml:7\r\nok: [localhost] => {\r\n    \"msg\": \"i execute normally\"\r\n}\r\n\r\nTASK [include] *****************************************************************\r\ntask path: /home/max/repos/lookup-ansible/block-test.yml:8\r\nincluded: /home/max/repos/lookup-ansible/test-fail.yml for localhost\r\n\r\nTASK [command] *****************************************************************\r\ntask path: /home/max/repos/lookup-ansible/test-fail.yml:1\r\nESTABLISH LOCAL CONNECTION FOR USER: max\r\n127.0.0.1 EXEC /bin/sh -c '( umask 22 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1463994871.45-243613082978293 `\" && echo \"` echo $HOME/.ansible/tmp/ansible-tmp-1463994871.45-243613082978293 `\" )'\r\n127.0.0.1 PUT /tmp/tmp2_rx5D TO /home/max/.ansible/tmp/ansible-tmp-1463994871.45-243613082978293/command\r\n127.0.0.1 EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/max/.ansible/tmp/ansible-tmp-1463994871.45-243613082978293/command; rm -rf \"/home/max/.ansible/tmp/ansible-tmp-1463994871.45-243613082978293/\" > /dev/null 2>&1'\r\nfatal: [localhost]: FAILED! => {\"changed\": true, \"cmd\": [\"/bin/false\"], \"delta\": \"0:00:00.001532\", \"end\": \"2016-05-23 11:14:31.497492\", \"failed\": true, \"invocation\": {\"module_args\": {\"_raw_params\": \"/bin/false\", \"_uses_shell\": false, \"chdir\": null, \"creates\": null, \"executable\": null, \"removes\": null, \"warn\": true}, \"module_name\": \"command\"}, \"rc\": 1, \"start\": \"2016-05-23 11:14:31.495960\", \"stderr\": \"\", \"stdout\": \"\", \"stdout_lines\": [], \"warnings\": []}\r\n        to retry, use: --limit @block-test.retry\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=3    changed=0    unreachable=0    failed=1   \r\n```\r\n\r\n##### THE INCLUDE IS TO BLAME\r\nIf I change the playbook to not use a include, and instead inline the `- command: /bin/false`, then it works as expected. \r\n\r\n```\r\n---\r\n\r\n- hosts: localhost\r\n\r\n  tasks:\r\n    - block:\r\n      - debug: msg='i execute normally'\r\n      #- include: test-fail.yml\r\n      - command: /bin/false\r\n      - debug: msg='i never execute, cause ERROR!'\r\n      always:\r\n      - debug: msg='in always section'\r\n```\r\n\r\nResult:\r\n\r\n```\r\nPLAY ***************************************************************************\r\n\r\nTASK [setup] *******************************************************************\r\nok: [localhost]\r\n\r\nTASK [debug] *******************************************************************\r\nok: [localhost] => {\r\n    \"msg\": \"i execute normally\"\r\n}\r\n\r\nTASK [command] *****************************************************************\r\nfatal: [localhost]: FAILED! => {\"changed\": true, \"cmd\": [\"/bin/false\"], \"delta\": \"0:00:00.001376\", \"end\": \"2016-05-23 11:40:39.351206\", \"failed\": true, \"rc\": 1, \"start\": \"2016-05-23 11:40:39.349830\", \"stderr\": \"\", \"stdout\": \"\", \"stdout_lines\": [], \"warnings\": []}\r\n\r\nTASK [debug] *******************************************************************\r\nok: [localhost] => {\r\n    \"msg\": \"in always section\"\r\n}\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=3    changed=0    unreachable=0    failed=0   \r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/247367788","html_url":"https://github.com/ansible/ansible/issues/15963#issuecomment-247367788","issue_url":"https://api.github.com/repos/ansible/ansible/issues/15963","id":247367788,"user":{"login":"kustodian","id":1949229,"avatar_url":"https://avatars.githubusercontent.com/u/1949229?v=3","gravatar_id":"","url":"https://api.github.com/users/kustodian","html_url":"https://github.com/kustodian","followers_url":"https://api.github.com/users/kustodian/followers","following_url":"https://api.github.com/users/kustodian/following{/other_user}","gists_url":"https://api.github.com/users/kustodian/gists{/gist_id}","starred_url":"https://api.github.com/users/kustodian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kustodian/subscriptions","organizations_url":"https://api.github.com/users/kustodian/orgs","repos_url":"https://api.github.com/users/kustodian/repos","events_url":"https://api.github.com/users/kustodian/events{/privacy}","received_events_url":"https://api.github.com/users/kustodian/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T15:48:56Z","updated_at":"2016-09-15T15:48:56Z","body":"Here is a repro which I have, it's a little different:\r\n\r\n```\r\n# test_blocks.yml\r\n---\r\n- hosts: localhost\r\n  connection: local\r\n  tasks:\r\n    - include: blocks.yml\r\n```\r\n```\r\n# blocks.yml\r\n- block:\r\n    - fail: msg='This will fail'\r\n  always:\r\n    - debug: msg='This will execute and stop'\r\n\r\n- debug: msg=\"This shouldn't be executed\"\r\n```\r\nWhen I run this command against latest `stable-2.1` branch:\r\n```\r\nansible-playbook -i localhost, test_blocks.yml -vvv\r\n```\r\nI get this output:\r\n```\r\nPLAYBOOK: test_blocks.yml ******************************************************\r\n1 plays in test_blocks.yml\r\n\r\nPLAY [localhost] ***************************************************************\r\n\r\nTASK [setup] *******************************************************************\r\n<localhost> ESTABLISH LOCAL CONNECTION FOR USER: user\r\n<localhost> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python && sleep 0'\r\nok: [localhost]\r\n\r\nTASK [fail] ********************************************************************\r\ntask path: /home/user/git/ansible-server-deploy/ansible_playbooks/blocks.yml:2\r\nfatal: [localhost]: FAILED! => {\"changed\": false, \"failed\": true, \"invocation\": {\"module_args\": {\"msg\": \"This will fail\"}, \"module_name\": \"fail\"}, \"msg\": \"This will fail\"}\r\nERROR! Unexpected Exception: min() arg is an empty sequence\r\nthe full traceback was:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/user/git/ansible-devel/bin/ansible-playbook\", line 92, in <module>\r\n    exit_code = cli.run()\r\n  File \"/home/user/git/ansible-devel/lib/ansible/cli/playbook.py\", line 154, in run\r\n    results = pbex.run()\r\n  File \"/home/user/git/ansible-devel/lib/ansible/executor/playbook_executor.py\", line 146, in run\r\n    result = self._tqm.run(play=play)\r\n  File \"/home/user/git/ansible-devel/lib/ansible/executor/task_queue_manager.py\", line 264, in run\r\n    play_return = strategy.run(iterator, play_context)\r\n  File \"/home/user/git/ansible-devel/lib/ansible/plugins/strategy/linear.py\", line 174, in run\r\n    host_tasks = self._get_next_task_lockstep(hosts_left, iterator)\r\n  File \"/home/user/git/ansible-devel/lib/ansible/plugins/strategy/linear.py\", line 73, in _get_next_task_lockstep\r\n    (s.cur_block for h, (s, t) in host_tasks_to_run\r\nValueError: min() arg is an empty sequence\r\n```"}}
{"actor":{"display_login":"kustodian"}}