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

ansible: environment difference while running debops playbooks #122

Open
dw opened this issue Mar 10, 2018 · 9 comments
Open

ansible: environment difference while running debops playbooks #122

dw opened this issue Mar 10, 2018 · 9 comments
Labels
ansible Issues relating to Mitogen for Ansible bug Code feature that hinders desired execution outcome NeedsTest Label for in-progress and closed bugs that do not yet have a corresponding regression test

Comments

@dw
Copy link
Member

dw commented Mar 10, 2018

Found while working on #110. My bashrc environment sets en_GB.UTF-8. When running with Mitogen, the run completes, but with non-Mitogen, then run fails with:

TASK [debops.sshd : Check if OpenSSH is installed (or half-installed)] *************************************************************************************************************
fatal: [35.200.184.46]: FAILED! => {"changed": false, "failed": true, "failed_when_result": true, "rc": 0, "stderr": "Shared connection to 35.200.184.46 closed.\r\n", "stdout": "bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)\r\ninstalled\r\n", "stdout_lines": ["bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)", "installed"]}

Because the Ansible master's environment is getting copied across somehow, and the locale data was missing on the target box. Figure out what's happening

@dw dw added bug Code feature that hinders desired execution outcome ansible Issues relating to Mitogen for Ansible labels Mar 10, 2018
@dw dw added this to the ansible_mitogen 0.0.1 milestone Mar 10, 2018
@stefangweichinger
Copy link

had that debops.sshd issue as well here. Just fyi.

@drybjed
Copy link

drybjed commented Mar 10, 2018

If it works with Mitogen (I wonder how) but doesn't work without it, it seems like the dpkg command doesn't like to use non-existent locales. Your en_gb.UTF-8 locale is passed through SSH because by default LC_* environment variables are whitelisted by sshd.

Perhaps setting the environment as LC_ALL: C for this task could solve it.

dw added a commit that referenced this issue Mar 10, 2018
@dw
Copy link
Member Author

dw commented Mar 10, 2018

I just pushed issue_122.yml which I was using earlier to try and reproduce the difference. Running vimdiff on the output with/without Mitogen shows no environment difference. Probably I'm still doing something wrong to reproduce the original scenario, will look at it later in the week.

No matter what the current behaviour is, Mitogen needs to emulate it. It needs to let both the SSH invocation and the sudo invocation do whatever horridness is done to the environment and reproduce exactly that, otherwise more playbooks will be broken behind closed doors

@drybjed
Copy link

drybjed commented Mar 11, 2018

@dw Ah, so you want to make sure that Mitogen fails the same way that Ansible fails with the same environment, good idea.

@dw
Copy link
Member Author

dw commented Mar 11, 2018

Discoveries so far:

  • OS X ssh_config does not have SendEnv by default
  • Debian ssh_config has SendEnv by default in /etc/ssh/ssh_config
  • Fedora ssh_config sets SendEnv in /etc/ssh/ssh_config.d/05-redhat.conf

As usual the correct behaviour isn't exactly clear. I dislike having bits of the environment leak into the tooling (it makes it impossible to test), but we have to emulate Ansible.

Relevant bugs:

Relevant spaghetti:

  • C.CONTROLER_LANG is set from LANG environment variable
  • C.DEFAULT_MODULE_LANG defaults to C.CONTROLER_LANG unless ANSIBLE_MODULE_LANG is present in the environment, or module_lang is present in [defaults] in ansible.cfg
  • plugins/shell/__init__.py uses C.DEFAULT_MODULE_LANG or (lol) the LANG environment variable if C.DEFAULT_MODULE_LANG is unset, to build a dict of defaults environment variables for any shell command. The dict contains LANG, LC_ALL and LC_MESSAGES forced to that value, but it only does this if C.DEFAULT_MODULE_SET_LOCALE is set, which is set if the ANSIBLE_MODULE_SET_LOCALE environment variable is set, or the module_set_locale key exists in [defaults] of ansible.cfg.
  • plugins/action/__init__.py uses ShellBase.env_prefix() from _compute_environment_string() to build the snippet for setting the environment using the active shell, but _compute_environment_string() does not return those variables in its output dictionary, only in the returned snippet.
  • plugins/action/__init__.py calls _compute_environment_string() from _execute_module() only. _low_level_execute_command() does not get this environment treatment

Sphaghetti round 2:

  • actions/script.py (which is the failing action) is not actually using _execute_module(), but calling _compute_environment_string() directly.

Can't reproduce this locally, going to have to setup two Gcloud boxes again

@dw
Copy link
Member Author

dw commented Mar 11, 2018

@stefangweichinger do you still have access to your setup that triggered the locale error? If so, can you please --start-at="Check if OpenSSH is installed (or half-installed)" and attach "-vvv" output both for Ansible and for Mitogen.

If not don't worry, I'll pick this up next week

@stefangweichinger
Copy link

@dw yes, I have. pls more details: with or without your new debug variable exported, mitogen.log from controller?

@dw
Copy link
Member Author

dw commented Mar 11, 2018

Just -vvv is fine, MITOGEN_ROUTER_DEBUG is only useful for lower level IO issues

@stefangweichinger
Copy link

stefangweichinger commented Mar 11, 2018

ansible-playbook ~/.local/share/debops/debops/ansible/playbooks/common.yml -vvv --start-at="Check if OpenSSH is installed (or half-installed)" -l tx100 > debops_common.log

debops_common.log

can't find a mitogen.log in /tmp now, though

note: afk soon ...

@dw dw added the NeedsTest Label for in-progress and closed bugs that do not yet have a corresponding regression test label Mar 12, 2018
dw added a commit that referenced this issue Mar 19, 2018
@dw dw removed this from the ansible_mitogen 0.0.1 milestone Oct 5, 2018
PatrickCoakley23 pushed a commit to cyara/mitogen that referenced this issue Nov 10, 2023
Signed-off-by: Dhaval <dhaval.indrodiya@spearline.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ansible Issues relating to Mitogen for Ansible bug Code feature that hinders desired execution outcome NeedsTest Label for in-progress and closed bugs that do not yet have a corresponding regression test
Projects
None yet
Development

No branches or pull requests

3 participants