{"action":"closed","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/15552","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/15552/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/15552/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/15552/events","html_url":"https://github.com/ansible/ansible/issues/15552","id":150435188,"number":15552,"title":"script over a chroot connection fails because it expects a shell execution environment","user":{"login":"mikedanese","id":1787169,"avatar_url":"https://avatars.githubusercontent.com/u/1787169?v=3","gravatar_id":"","url":"https://api.github.com/users/mikedanese","html_url":"https://github.com/mikedanese","followers_url":"https://api.github.com/users/mikedanese/followers","following_url":"https://api.github.com/users/mikedanese/following{/other_user}","gists_url":"https://api.github.com/users/mikedanese/gists{/gist_id}","starred_url":"https://api.github.com/users/mikedanese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikedanese/subscriptions","organizations_url":"https://api.github.com/users/mikedanese/orgs","repos_url":"https://api.github.com/users/mikedanese/repos","events_url":"https://api.github.com/users/mikedanese/events{/privacy}","received_events_url":"https://api.github.com/users/mikedanese/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-22T18:05:40Z","updated_at":"2016-04-22T18:22:54Z","closed_at":"2016-04-22T18:22:53Z","body":"I could not find a similar issue\r\n##### ISSUE TYPE\r\n - Bug Report\r\n\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nroot@9dcc119a2644:/# ansible --version\r\nansible 1.7.2\r\n```\r\n\r\n##### CONFIGURATION\r\n\r\nconnection=chroot\r\n\r\n##### OS / ENVIRONMENT\r\n\r\njessie host, ubuntu chroot\r\n\r\n##### SUMMARY\r\n\r\nUsing `script` over a chroot fails. Here are the verbose logs:\r\n\r\n```\r\nPLAY [node] ******************************************************************* \r\n\r\nGATHERING FACTS *************************************************************** \r\n</host_root> THIS IS A LOCAL CHROOT DIR\r\n</host_root> REMOTE_MODULE setup\r\n</host_root> EXEC ['/usr/sbin/chroot', '/host_root', '/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1461347830.72-107156131762630 && echo $HOME/.ansible/tmp/ansible-tmp-1461347830.72-107156131762630']\r\n</host_root> PUT /tmp/tmpX2oR5D TO /host_root/root/.ansible/tmp/ansible-tmp-1461347830.72-107156131762630/setup\r\n</host_root> EXEC ['/usr/sbin/chroot', '/host_root', '/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1461347830.72-107156131762630/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1461347830.72-107156131762630/ >/dev/null 2>&1']\r\nok: [/host_root]\r\n\r\nTASK: [init | script maybe_install_python.sh] ********************************* \r\n</host_root> THIS IS A LOCAL CHROOT DIR\r\n</host_root> EXEC ['/usr/sbin/chroot', '/host_root', '/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717 && echo $HOME/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717']\r\n</host_root> PUT /opt/ansible/playbooks/roles/init/files/maybe_install_python.sh TO /host_root/root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh\r\n</host_root> EXEC ['/usr/sbin/chroot', '/host_root', '/bin/sh', '-c', u'chmod +rx /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh']\r\n</host_root> EXEC /usr/sbin/chroot \"/host_root\" LANG=C LC_CTYPE=C /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh\r\n</host_root> EXEC ['/usr/sbin/chroot', '/host_root', '/bin/sh', '-c', 'rm -rf /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/ >/dev/null 2>&1']\r\nfailed: [/host_root] => {\"changed\": true, \"rc\": 127}\r\nstderr: /usr/sbin/chroot: failed to run command 'LANG=C': No such file or directory\r\n\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n```\r\n\r\nThe issue is this line:\r\n\r\n```\r\n</host_root> EXEC /usr/sbin/chroot \"/host_root\" LANG=C LC_CTYPE=C /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh\r\n```\r\n\r\nChroot does not exec commands inside a shell like ssh does, so LANG=C is interpretted as a path to an executable. Running the command directly fails:\r\n\r\n```\r\nroot@34bc991735ad:/# /usr/sbin/chroot \"/host_root\" LANG=C LC_CTYPE=C /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh\r\n/usr/sbin/chroot: failed to run command 'LANG=C': No such file or directory\r\n```\r\n\r\nAdding an sh execution would succeed if the script hadn't been cleaned up:\r\n\r\n```\r\nroot@34bc991735ad:/# /usr/sbin/chroot \"/host_root\" /bin/bash -c \"LANG=C LC_CTYPE=C /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh\"                                                               \r\n/bin/bash: /root/.ansible/tmp/ansible-tmp-1461347835.03-129812292718717/maybe_install_python.sh: No such file or directory\r\n```\r\n"}}