【问题标题】:ansible-playbook -> ControlPath too longansible-playbook -> ControlPath 太长
【发布时间】:2015-02-13 17:50:01
【问题描述】:

我只是想找到一个同事设置的剧本,我需要修改它。我在 Mac 上遇到的第一个问题是

ERROR: Unable to find an inventory file, specify one with -i ?

通过在命令中添加 -i verif 很容易解决这个问题。但随后出现以下错误。

loadgen-verif-app1.internal.machines | FAILED => SSH encountered an unknown error. The output was:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/andreas.joelsson/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
ControlPath too long

这适用于所有 8 台机器 (loadgen-verif-app[1-8].internal.machines)

经过一些调试文件可能太长,我尝试了以下命令,结果相同:

ansible nukes -m ping -i verif -vvvv

然后我认为这是 ssh 的问题,但通过 ssh 执行命令有效:

ssh loadgen-verif-app1.internal.machines ping loadgen-verif-app2.internal.machines

现在我很困惑,因为 ping 命令在一些不在上面列出的范围内的机器上工作,问题是它们比 loagenXXX.machines 路径短,如果这使它成为问题。但是我猜 ssh 命令应该不起作用。

我也为目标设置了一些 ssh 配置设置,但这与使用 ping 命令的设置没有什么不同。

Host loadgen1
    HostName loadgen-verif-app1.internal.machines

现在我很困惑,因为它也适用于 Mac 上的同事。所以不确定是否有一些我缺少或类似的设置。他不需要提供 -i 验证,这也可能是它不起作用的原因。

编辑 2014-12-17:

编辑 2015-01-08:

SE-C02N76PGG5RP:verif_provisioning andreas.joelsson$ ansible loadgen-verif-app1.internal.machines -m ping -i verif -vvvv
<loadgen-verif-app1.internal.machines> ESTABLISH CONNECTION FOR USER: andreas.joelsson
<loadgen-verif-app1.internal.machines> REMOTE_MODULE ping
<loadgen-verif-app1.internal.machines> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/andreas.joelsson/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 loadgen-verif-app1.internal.machines /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1420723708.99-33622628424665 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1420723708.99-33622628424665 && echo $HOME/.ansible/tmp/ansible-tmp-1420723708.99-33622628424665'
loadgen-verif-app1.internal.machines | FAILED => SSH encountered an unknown error. The output was:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/andreas.joelsson/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
ControlPath too long

编辑 2015-02-12:

SE-C02N76PGG5RP:verif_provisioning andreas.joelsson$ ansible nukes -m ping -i verif
loadgen-verif-app4.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app5.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app3.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app1.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app2.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app8.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app6.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
loadgen-verif-app7.internal.machines | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue

还有工作的:

SE-C02N76PGG5RP:verif_provisioning andreas.joelsson$ ansible duke -m ping -i verif
steve-verif-app1.internal.machines | success >> {
    "changed": false,
    "ping": "pong"
}

【问题讨论】:

  • 您的同事是否向您发送了他的 ansible.cfg 文件,结果您的 Mac 上的正确位置是否有所有相同(和相关)的配置文件?这似乎是要检查的第一件事......
  • 与我签出的 git repo 中的配置相同,还有其他地方可以存储设置吗?
  • 除了命令行选项之外,配置在 ansible.cfg 文件中说明 - 您可能需要检查您使用的是相同版本的 ansible(我认为是 ansible -v)。
  • 是的,现在使用相同的版本,或者我使用了他升级到相同结果的新版本,我们认为这是控制路径的 ssh 问题,但做出了 ansible 建议的更改什么都没有(docs.ansible.com/intro_configuration.html#control-path)。

标签: macos ssh yaml ansible


【解决方案1】:

ansible文档中提到了这个错误的解决方法,请参考这个link

当我尝试连接到 EC2 实例时遇到此错误,但在修改了下面提到的配置后,它解决了我的问题。

我假设您已经使用 pip 在 Mac 上安装了 ansible。所以,请执行以下步骤:

  1. 创建/etc/ansible 目录

    sudo mkdir /etc/ansible
    
  2. 改变它的权限

    sudo chown $(whoami):staff /etc/ansible
    
  3. here下载ansible.cfg文件并放在/etc/ansible目录中

  4. 编辑/取消注释以下行

    [ssh_connection]
    control_path = %(directory)s/%%h-%%r
    
  5. 编辑~/.ssh/config 文件:

    Host *
      GSSAPIAuthentication no
    

额外步骤:

brew install https://raw.github.com/eugeneoden/homebrew/eca9de1/Library/Formula/sshpass.rb

【讨论】:

  • 我用brew安装。在我有 ansible 的 git repo 的根目录中,我在默认情况下添加了 control_path,例如: [defaults] roles_path = roles control_path = %(directory)s/%%h-%%r
  • 这对您有用还是您遇到任何问题?
  • 我没有试过你的解决方案,本地的路径也不行。 brew 是否相同,所以我应该添加您建议的步骤?
  • 尝试您的建议,但也没有奏效。修改配置后,似乎主机名太长了。我可以访问名称为:steve-verif-app1.internal.machines 的主机名,但不能访问名称为 loadgen-verif-app1.internal.machines 的主机名。我试图缩短 .ssh/config 和 /etc/hosts 中的名称,但没有任何运气。
  • 您能否使用 -vvvv 运行并分享结果。谢谢
【解决方案2】:

好吧,我让它工作的方式是我在ansible.cfg 中进行了更改以及额外的步骤,但它不起作用。我发现的唯一方法是导出ANSIBLE_SSH_CONTROL_PATH

这是因为,我认为它总是选择默认路径。即使在ansible.cfg 发生变化之后

  1.9.4 git:(master) pwd                                                                                                                                            
/usr/local/Cellar/ansible/1.9.4
➜  1.9.4 git:(master) ag ANSIBLE_SSH_CONTROL
libexec/lib/python2.7/site-packages/ansible/constants.py
187:ANSIBLE_SSH_CONTROL_PATH       = get_config(p, 'ssh_connection', 'control_path', 'ANSIBLE_SSH_CONTROL_PATH', "%(directory)s/ansible-ssh-%%h-%%p-%%r")

输出不导出ANSIBLE_SSH_CONTOL_PATH:

ControlPath="/Users/vinitkhandagle/.ansible/cp/ansible-ssh-%h-%p-%r"

将变量导出为:

export ANSIBLE_SSH_CONTROL_PATH='%(directory)s/%%h-%%r'

控制路径相应改变:

ControlPath="/Users/vinitkhandagle/.ansible/cp/%h-%r"

【讨论】:

    猜你喜欢
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 2017-09-29
    相关资源
    最近更新 更多