{"action":"opened","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/18043","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/18043/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/18043/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/18043/events","html_url":"https://github.com/ansible/ansible/issues/18043","id":183223494,"number":18043,"title":"Ansible connects via SSH to localhost if it's defined in the inventory","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},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-15T18:01:30Z","updated_at":"2016-10-15T18:01:30Z","closed_at":null,"body":"##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### ANSIBLE VERSION\r\n```\r\n2.1.2\r\n```\r\nThe issue also persists in `devel` and `stable-2.1`\r\n\r\n##### CONFIGURATION\r\nNot important\r\n\r\n##### OS / ENVIRONMENT\r\nNot important\r\n\r\n##### SUMMARY\r\nIf `localhost` is defined in the inventory, Ansible will connect to it using SSH, instead of the local connection.\r\n\r\n##### STEPS TO REPRODUCE\r\nAdd localhost to the inventory.\r\n```ini\r\n# hosts.ini\r\nlocalhost\r\n```\r\nCreate test.yml:\r\n```yml\r\n# test.yml\r\n---\r\n- hosts: localhost\r\n  tasks:\r\n    - debug: msg=Hello\r\n```\r\nRun this playbook first without specifying an inventory:\r\n```\r\n$ ansible-playbook test.yml -vvv\r\nUsing /etc/ansible/ansible.cfg as config file\r\n [WARNING]: provided hosts list is empty, only localhost is available\r\n\r\n\r\nPLAYBOOK: test.yml *************************************************************\r\n1 plays in test.yml\r\n\r\nPLAY [localhost] ***************************************************************\r\n\r\nTASK [setup] *******************************************************************\r\nUsing module file /home/user/git/ansible-devel/lib/ansible/modules/core/system/setup.py\r\n<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user\r\n<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616 `\" && echo ansible-tmp-1476553978.66-162661035281616=\"` echo $HOME/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616 `\" ) && sleep 0'\r\n<127.0.0.1> PUT /tmp/tmpTfd1xL TO /home/user/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616/setup.py\r\n<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616/ /home/user/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616/setup.py && sleep 0'\r\n<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/user/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616/setup.py; rm -rf \"/home/user/.ansible/tmp/ansible-tmp-1476553978.66-162661035281616/\" > /dev/null 2>&1 && sleep 0'\r\nok: [localhost]\r\n\r\nTASK [debug] *******************************************************************\r\ntask path: /home/user/temp/test.yml:4\r\nok: [localhost] => {\r\n    \"msg\": \"Hello\"\r\n}\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=2    changed=0    unreachable=0    failed=0\r\n```\r\nNow run the same command, but pass the inventory:\r\n```\r\n$ ansible-playbook -i hosts.ini test.yml -vvv \r\nUsing /etc/ansible/ansible.cfg as config file\r\n\r\nPLAYBOOK: test.yml *************************************************************\r\n1 plays in test.yml\r\n\r\nPLAY [localhost] ***************************************************************\r\n\r\nTASK [setup] *******************************************************************\r\nUsing module file /home/user/git/ansible-devel/lib/ansible/modules/core/system/setup.py\r\n<localhost> ESTABLISH SSH CONNECTION FOR USER: None\r\n<localhost> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/user/.ansible/cp/ansible-ssh-%h-%p-%r localhost '/bin/sh -c '\"'\"'( umask 77 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1476554101.44-258630782326921 `\" && echo ansible-tmp-1476554101.44-258630782326921=\"` echo $HOME/.ansible/tmp/ansible-tmp-1476554101.44-258630782326921 `\" ) && sleep 0'\"'\"''\r\nfatal: [localhost]: UNREACHABLE! => {\r\n    \"changed\": false, \r\n    \"msg\": \"Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\\r\\n@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @\\r\\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\\r\\nIT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\\r\\nSomeone could be eavesdropping on you right now (man-in-the-middle attack)!\\r\\nIt is also possible that a host key has just been changed.\\r\\nThe fingerprint for the ECDSA key sent by the remote host is\\nSHA256:Dv/IiOpXIhfAL2s2kPuRTYJLFBCOGMEok9NUGCY/u2M.\\r\\nPlease contact your system administrator.\\r\\nAdd correct host key in /home/user/.ssh/known_hosts to get rid of this message.\\r\\nOffending ECDSA key in /home/user/.ssh/known_hosts:338\\r\\n  remove with:\\r\\n  ssh-keygen -f \\\"/home/user/.ssh/known_hosts\\\" -R localhost\\r\\nECDSA host key for localhost has changed and you have requested strict checking.\\r\\nHost key verification failed.\\r\\n\", \r\n    \"unreachable\": true\r\n}\r\n        to retry, use: --limit @/home/user/temp/test.retry\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=0    changed=0    unreachable=1    failed=0\r\n```\r\n\r\n##### EXPECTED RESULTS\r\nAnsible should connect to localhost using `local` connection by default, like it always did.\r\n\r\n##### ACTUAL RESULTS\r\nIf `localhost` is defined in the inventory, Ansible uses SSH as the default for localhost.\r\n\r\nThe workaround for this issue is to use `localhost ansible_connection=local` in the inventory, but that should still be default for localhost.\r\n"}}
{"actor":{"display_login":"kustodian"}}