Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error caused by shell type #13459

Closed
wanopt opened this issue Dec 7, 2015 · 10 comments
Closed

fatal error caused by shell type #13459

wanopt opened this issue Dec 7, 2015 · 10 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@wanopt
Copy link

wanopt commented Dec 7, 2015

on mac 10.9.5, ansible versions > 1.9.4 has an error caused by default shell on remote freebsd 10.2 guest.

default ssh to freebsd seems to use csh and thus give the error as below. 1.9.4 works fine since it does not generate the echo portion like

echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118 )" ). 

<127.0.0.1> SSH: EXEC ssh -C -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2222 -o 'IdentityFile="/Users/t/.vagrant.d/insecure_private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/t/.ansible/cp/ansible-ssh-%h-%p-%r -tt 127.0.0.1 ( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118 )" )

vagrant@server:~ % umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118
Illegal variable name.

configured ssh shell on vagrant and inside ansible privisioner through ansible_shell_type but still got the error.

@bcoca bcoca added bug_report needs_info This issue requires further information. Please answer any outstanding questions. labels Dec 7, 2015
@wanopt
Copy link
Author

wanopt commented Dec 8, 2015

A temporary workaround for vagrant with freebsd 10.2 guest to work with ansible 2.0.0: manually changing the default shell of freebsd from csh to sh through vagrant builtin privision.

config.vm.define :server do |server|
....
server.vm.provision "shell",
run: "always",
inline: "chsh -s /bin/sh vagrant"
....
end

Something has changed at "mkdtemp" method for ansible versions > 1.9.4. The echo part echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118 )" ) from this method seems to have caused the problem for csh. Have not got time to dig into it though.

@bcoca
Copy link
Member

bcoca commented Dec 12, 2015

have you set ansible_shell_type=csh for that host?

@wanopt
Copy link
Author

wanopt commented Dec 12, 2015

No, I did not set ansible_shell_type=csh. I found that the worse part is that even when I make it NOT to be csh (e.g., sh), it seemed to have no effect. That made me to resort to vagrant provision instead.

@bcoca
Copy link
Member

bcoca commented Dec 12, 2015

if your target machine is using a csh type shell you need to set that var, otherwise ansible will use the default (sh) which will produce the error you show above.

if you don't want to set the var then changing the shell to sh is the other way to make it work.

Closing this as it seems to just be a misunderstanding on the shell settings.

@bcoca bcoca closed this as completed Dec 12, 2015
@wanopt
Copy link
Author

wanopt commented Dec 12, 2015

Does version 1.9.4 work with csh out of box?

@wanopt
Copy link
Author

wanopt commented Dec 12, 2015

In my test, 1.9.4 works with the target machine and 2.0 does not. I see some changes in "mkdtemp" method for ansible versions > 1.9.4 causes the problem.

@bcoca
Copy link
Member

bcoca commented Dec 12, 2015

tested latest stable-2.0 and it works, there were versions of 2.0 in which this was broken, can you use latest?

@wanopt
Copy link
Author

wanopt commented Dec 12, 2015

Looks like the method below (from version > 1.9.4) caused the problem. It issued a command like umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1449517181.33-230267840450118 through ssh. The command gives the error Illegal variable name. if being run under csh, same with the error reported from ansible. I checked 1.9.4 and the generated command from mkdtemp(1.9.4) is different and seems to able to succeed on csh. The method I referred to is in lib/ansible/plugins/shell/sh.py, which has been changed from 1.9.4 to 2.0.0. You may have the reason to change it. I just noticed that this change make it fail on csh.

    def mkdtemp(self, basefile=None, system=False, mode=None):
        if not basefile:
            basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48))
        basetmp = self.join_path(C.DEFAULT_REMOTE_TMP, basefile)
        if system and (basetmp.startswith('$HOME') or basetmp.startswith('~/')):
            basetmp = self.join_path('/tmp', basefile)
        cmd = 'mkdir -p %s echo %s %s' % (self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)
        cmd += ' %s echo %s echo %s %s' % (self._SHELL_AND, self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)

        # change the umask in a subshell to achieve the desired mode
        # also for directories created with `mkdir -p`
        if mode:
            tmp_umask = 0o777 & ~mode
            cmd = '%s umask %o %s %s %s' % (self._SHELL_GROUP_LEFT, tmp_umask, self._SHELL_AND, cmd, self._SHELL_GROUP_RIGHT)

        return cmd

@bcoca bcoca reopened this Dec 12, 2015
@bcoca bcoca added this to the v2 milestone Dec 12, 2015
@bcoca bcoca removed the needs_info This issue requires further information. Please answer any outstanding questions. label Dec 12, 2015
bcoca added a commit that referenced this issue Dec 12, 2015
@bcoca bcoca closed this as completed in 99e4644 Dec 12, 2015
@bcoca
Copy link
Member

bcoca commented Dec 12, 2015

pushed fix, this now works in stable-2.0 and devel also

@wanopt
Copy link
Author

wanopt commented Dec 13, 2015

Thanks!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants