{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/34665","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/34665/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/34665/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/34665/events","html_url":"https://github.com/ansible/ansible/issues/34665","id":287250967,"number":34665,"title":"Errors can be wrongly replaced on dynamically imported static include","user":{"login":"johnboy2","id":5591205,"avatar_url":"https://avatars1.githubusercontent.com/u/5591205?v=4","gravatar_id":"","url":"https://api.github.com/users/johnboy2","html_url":"https://github.com/johnboy2","followers_url":"https://api.github.com/users/johnboy2/followers","following_url":"https://api.github.com/users/johnboy2/following{/other_user}","gists_url":"https://api.github.com/users/johnboy2/gists{/gist_id}","starred_url":"https://api.github.com/users/johnboy2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnboy2/subscriptions","organizations_url":"https://api.github.com/users/johnboy2/orgs","repos_url":"https://api.github.com/users/johnboy2/repos","events_url":"https://api.github.com/users/johnboy2/events{/privacy}","received_events_url":"https://api.github.com/users/johnboy2/received_events","type":"User","site_admin":false},"labels":[{"id":562292166,"url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.4","name":"affects_2.4","color":"ededed","default":false},{"id":785271699,"url":"https://api.github.com/repos/ansible/ansible/labels/bug","name":"bug","color":"fbca04","default":true},{"id":496359346,"url":"https://api.github.com/repos/ansible/ansible/labels/module","name":"module","color":"1d76db","default":false},{"id":636352796,"url":"https://api.github.com/repos/ansible/ansible/labels/support:core","name":"support:core","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-01-09T22:21:34Z","updated_at":"2018-04-25T21:59:02Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"<!---\r\nVerify first that your issue/request is not already reported on GitHub.\r\nAlso test if the latest release, and master branch are affected too.\r\n-->\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\ninclude_tasks\r\n\r\n##### ANSIBLE VERSION\r\n<!--- Paste verbatim output from \"ansible --version\" between quotes below -->\r\n```\r\nansible 2.4.2.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = [u'/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /usr/lib/python2.7/dist-packages/ansible\r\n  executable location = /usr/bin/ansible\r\n  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]\r\n```\r\n\r\n##### CONFIGURATION\r\n```\r\nANSIBLE_PIPELINING(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True\r\nANSIBLE_SSH_ARGS(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=300s -o UserKnownHostsFile=./ssh_known_hosts\r\nDEFAULT_BECOME(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = True\r\nDEFAULT_LOG_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = /mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.log\r\nDEFAULT_REMOTE_USER(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = automation\r\nDEFAULT_ROLES_PATH(/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/ansible.cfg) = [u'/mnt/speedyg/johnn/Documents/EclipseWS/cloud-network/roles']\r\n```\r\n\r\n##### OS / ENVIRONMENT\r\nManagement node: Ubuntu 16.04\r\nRemote node: Debian 9\r\n\r\n##### SUMMARY\r\nUntrue/incorrect error message shown when a dynamically-determined dynamic include contains an embedded reference to an unknown file.\r\n\r\n##### STEPS TO REPRODUCE\r\n<!---\r\nFor bugs, show exactly how to reproduce the problem, using a minimal test-case.\r\nFor new features, show how the feature would be used.\r\n-->\r\n\r\n<!--- Paste example playbooks or commands between quotes below -->\r\ntest.yml:\r\n```yaml\r\n- hosts: all\r\n  tasks:\r\n  - debug: var=ansible_system\r\n  - include_tasks: '{{ ansible_system }}.yml'\r\n```\r\n\r\nLinux.yml:\r\n```yaml\r\n- import_tasks: a_file_that_does_not_exist.yml\r\n```\r\n\r\nExecute command:\r\n```\r\nansible-playbook -l \"pick_an_inventory_host\" test.yml\r\n```\r\n\r\n##### EXPECTED RESULTS\r\nThe debug task should execute as expected, showing the remote system's platform (expected in this case to be \"Linux\").\r\n\r\nFor the \"include_tasks\" task, it should result in an error along the lines of:\r\n```\r\nFAILED! => {\"reason\": \"Unable to retrieve file contents\\nCould not find or access '...'\"}\r\n```\r\n(which is what you get with a straight-up static include of a missing file)\r\n\r\n##### ACTUAL RESULTS\r\nDebug task executes as expected (which also proves that ```ansible_system``` is defined).\r\n\r\nThe \"import_tasks\" task fails, as expected, but does so with an entirely incorrect error message:\r\n```\r\nFAILED! => {\"reason\": \"'ansible_system' is undefined\"}\r\n```\r\n\r\nAnsible thus **hides** the actual fault in this case behind a completely false error.\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/384447617","html_url":"https://github.com/ansible/ansible/issues/34665#issuecomment-384447617","issue_url":"https://api.github.com/repos/ansible/ansible/issues/34665","id":384447617,"user":{"login":"sivel","id":39340,"avatar_url":"https://avatars3.githubusercontent.com/u/39340?v=4","gravatar_id":"","url":"https://api.github.com/users/sivel","html_url":"https://github.com/sivel","followers_url":"https://api.github.com/users/sivel/followers","following_url":"https://api.github.com/users/sivel/following{/other_user}","gists_url":"https://api.github.com/users/sivel/gists{/gist_id}","starred_url":"https://api.github.com/users/sivel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sivel/subscriptions","organizations_url":"https://api.github.com/users/sivel/orgs","repos_url":"https://api.github.com/users/sivel/repos","events_url":"https://api.github.com/users/sivel/events{/privacy}","received_events_url":"https://api.github.com/users/sivel/received_events","type":"User","site_admin":false},"created_at":"2018-04-25T21:59:02Z","updated_at":"2018-04-25T21:59:02Z","author_association":"MEMBER","body":"A not so correct solution, but a solution nonetheless:\r\n\r\n```diff\r\ndiff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py\r\nindex 248a840bb0..6518ace88f 100644\r\n--- a/lib/ansible/playbook/helpers.py\r\n+++ b/lib/ansible/playbook/helpers.py\r\n@@ -178,7 +178,10 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h\r\n                         if not isinstance(parent_include, TaskInclude):\r\n                             parent_include = parent_include._parent\r\n                             continue\r\n-                        parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))\r\n+                        try:\r\n+                            parent_include_dir = os.path.dirname(templar.template(parent_include.args.get('_raw_params')))\r\n+                        except AnsibleUndefinedVariable:\r\n+                            parent_include_dir = ''\r\n                         if cumulative_path is None:\r\n                             cumulative_path = parent_include_dir\r\n                         elif not os.path.isabs(cumulative_path):\r\n```\r\n\r\nIdeally we would have to implement some form of path inheritance that didn't depend on host context. Which would mean every consolidated include result, would need a unique parent with vars pre-resolved for later.\r\n\r\nThat isn't a fix that is simple, and not something that can make it into 2.6.\r\n\r\nThe above fix just does the best we can, and assumes that the included file is immediately relative."}}
{"actor":{"display_login":"sivel"}}