{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/31595","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/31595/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/31595/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/31595/events","html_url":"https://github.com/ansible/ansible/issues/31595","id":264681464,"node_id":"MDU6SXNzdWUyNjQ2ODE0NjQ=","number":31595,"title":"Ansible fails to find ansible_* vars in playbook imported from subdir when running with host list (-i host1,)","user":{"login":"x-yuri","id":730588,"node_id":"MDQ6VXNlcjczMDU4OA==","avatar_url":"https://avatars0.githubusercontent.com/u/730588?v=4","gravatar_id":"","url":"https://api.github.com/users/x-yuri","html_url":"https://github.com/x-yuri","followers_url":"https://api.github.com/users/x-yuri/followers","following_url":"https://api.github.com/users/x-yuri/following{/other_user}","gists_url":"https://api.github.com/users/x-yuri/gists{/gist_id}","starred_url":"https://api.github.com/users/x-yuri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/x-yuri/subscriptions","organizations_url":"https://api.github.com/users/x-yuri/orgs","repos_url":"https://api.github.com/users/x-yuri/repos","events_url":"https://api.github.com/users/x-yuri/events{/privacy}","received_events_url":"https://api.github.com/users/x-yuri/received_events","type":"User","site_admin":false},"labels":[{"id":562292166,"node_id":"MDU6TGFiZWw1NjIyOTIxNjY=","url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.4","name":"affects_2.4","color":"ededed","default":false},{"id":785271699,"node_id":"MDU6TGFiZWw3ODUyNzE2OTk=","url":"https://api.github.com/repos/ansible/ansible/labels/bug","name":"bug","color":"fbca04","default":true},{"id":496359346,"node_id":"MDU6TGFiZWw0OTYzNTkzNDY=","url":"https://api.github.com/repos/ansible/ansible/labels/module","name":"module","color":"1d76db","default":false},{"id":636352796,"node_id":"MDU6TGFiZWw2MzYzNTI3OTY=","url":"https://api.github.com/repos/ansible/ansible/labels/support:core","name":"support:core","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-10-11T18:03:27Z","updated_at":"2018-06-16T09:51:59Z","closed_at":"2018-04-17T19:47:20Z","author_association":"NONE","body":"This might have something to do with #29008, but I'm not sure about that.\r\n\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\nimport_playbook, probably\r\n\r\n##### ANSIBLE VERSION\r\n<!--- Paste verbatim output from \"ansible --version\" between quotes below -->\r\n```\r\nansible 2.4.0.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = [u'/home/yuri/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /usr/lib/python2.7/site-packages/ansible\r\n  executable location = /usr/bin/ansible\r\n  python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]\r\n```\r\n\r\n##### CONFIGURATION\r\n\r\n```\r\n$ ansible-config dump --only-changed\r\n<nothing>\r\n```\r\n\r\n##### OS / ENVIRONMENT\r\nArch Linux\r\n\r\n##### SUMMARY\r\nWhen running ansible without inventory (`-i host1,`) it doesn't seem to find `ansible_user`, `ansible_host` vars in an imported playbook, and tries to connect literally to `host1` (`ssh host1`).\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\n`playbook.yml`\r\n```yaml\r\n- import_playbook: 1/1.yml\r\n\r\n- hosts: all\r\n  gather_facts: no\r\n  tasks:\r\n    - import_tasks: 1/2.yml\r\n    - raw: echo test3\r\n```\r\n\r\n`host_vars/production`:\r\n```yaml\r\nansible_user: ...\r\nansible_host: ...\r\n```\r\n\r\n`1/1.yml`:\r\n```yaml\r\n- hosts: all\r\n  gather_facts: no\r\n  tasks:\r\n    - raw: echo test1\r\n```\r\n\r\n`1/2.yml`:\r\n```yaml\r\n- raw: echo test2\r\n```\r\n\r\n```\r\n$ ansible-playbook -i production, playbook.yml\r\nUsing /etc/ansible/ansible.cfg as config file\r\n\r\nPLAY [all] ************************************************************************************\r\n\r\nTASK [raw] ************************************************************************************\r\nfatal: [production]: UNREACHABLE! => {\"changed\": false, \"msg\": \"Failed to connect to the host via ssh: ssh: Could not resolve hostname production: Name or service not known\\r\\n\", \"unreachable\": true}\r\n        to retry, use: --limit @/home/yuri/_/1/playbook.retry\r\n\r\nPLAY RECAP ************************************************************************************\r\nproduction                 : ok=0    changed=0    unreachable=1    failed=0   \r\n```\r\n\r\n##### EXPECTED RESULTS\r\nIt succeeds\r\n\r\n##### ADDITIONAL INFO\r\nHere's [the archive][1] with the files to reproduce the issue. When run this way:\r\n\r\n```\r\n$ ansible-playbook -i hosts playbook.yml\r\nUsing /etc/ansible/ansible.cfg as config file\r\n\r\nPLAY [all] ************************************************************************************\r\n\r\nTASK [raw] ************************************************************************************\r\nchanged: [production] => {\"changed\": true, \"failed\": false, \"rc\": 0, \"stderr\": \"Shared connection to example.com closed.\\r\\n\", \"stdout\": \"test1\\r\\n\", \"stdout_lines\": [\"test1\"]}\r\n\r\nPLAY [all] ************************************************************************************\r\n\r\nTASK [raw] ************************************************************************************\r\nchanged: [production] => {\"changed\": true, \"failed\": false, \"rc\": 0, \"stderr\": \"Shared connection to example.com closed.\\r\\n\", \"stdout\": \"test2\\r\\n\", \"stdout_lines\": [\"test2\"]}\r\n\r\nTASK [raw] ************************************************************************************\r\nchanged: [production] => {\"changed\": true, \"failed\": false, \"rc\": 0, \"stderr\": \"Shared connection to example.com closed.\\r\\n\", \"stdout\": \"test3\\r\\n\", \"stdout_lines\": [\"test3\"]}\r\n\r\nPLAY RECAP ************************************************************************************\r\nproduction                 : ok=3    changed=3    unreachable=0    failed=0\r\n```\r\n\r\nIt succeeds.\r\n\r\n[1]: https://github.com/ansible/ansible/files/1376679/import-playbook-subdir-host-list.zip\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/397801582","html_url":"https://github.com/ansible/ansible/issues/31595#issuecomment-397801582","issue_url":"https://api.github.com/repos/ansible/ansible/issues/31595","id":397801582,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzgwMTU4Mg==","user":{"login":"x-yuri","id":730588,"node_id":"MDQ6VXNlcjczMDU4OA==","avatar_url":"https://avatars0.githubusercontent.com/u/730588?v=4","gravatar_id":"","url":"https://api.github.com/users/x-yuri","html_url":"https://github.com/x-yuri","followers_url":"https://api.github.com/users/x-yuri/followers","following_url":"https://api.github.com/users/x-yuri/following{/other_user}","gists_url":"https://api.github.com/users/x-yuri/gists{/gist_id}","starred_url":"https://api.github.com/users/x-yuri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/x-yuri/subscriptions","organizations_url":"https://api.github.com/users/x-yuri/orgs","repos_url":"https://api.github.com/users/x-yuri/repos","events_url":"https://api.github.com/users/x-yuri/events{/privacy}","received_events_url":"https://api.github.com/users/x-yuri/received_events","type":"User","site_admin":false},"created_at":"2018-06-16T09:51:59Z","updated_at":"2018-06-16T09:51:59Z","author_association":"NONE","body":"@sivel But then using inventory wouldn't make a difference, would it?"}}
{"actor":{"display_login":"x-yuri"}}