ssl - Vagrant,Ansible : SSLError bad handshake: Error SSL routines, ssl3_get_record,错误的版本号

标签 ssl ansible vagrant

我正在使用 Vagrant+Ansible 设置 Windows Server 2019 VM。

  • 主机操作系统:Ubuntu 20.10
  • Ansible:2.9.9
  • Vagrant :2.2.9

  • 我的 Vagrant 文件:
    Vagrant.configure("2") do |config|
      config.vm.box = "StefanScherer/windows_2019"
      config.vm.provision :ansible do |ansible|
        ansible.playbook = "provisioners/ansible/ansible_playbook.yml"
        ansible.config_file = "provisioners/ansible/ansible.cfg"
        ansible.become_user = "Administrator"
        ansible.raw_arguments = ["-e", "ansible_winrm_server_cert_validation=ignore"]
      end
    end
    
    我在 vagrant up --provision 上收到此错误:
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Checking if box 'StefanScherer/windows_2019' version '2020.09.22' is up to date...
    ==> default: Running provisioner: ansible...
        default: Running ansible-playbook...
    
    PLAY [Jenkins node playbook]
    ***************************************************
    
    TASK [Gathering Facts]
    *********************************************************
    Friday 29 January 2021  09:23:35 +0100 (0:00:00.023)       0:00:00.023 ********
    fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "ssl:
    HTTPSConnectionPool(host='127.0.0.1', port=55985): Max retries exceeded with
    url: /wsman (Caused by SSLError(SSLError(\"bad handshake: Error([('SSL routines',
    'ssl3_get_record', 'wrong version number')])\")))", "unreachable": true}
    
    PLAY RECAP
    *********************************************************************
    default                    : ok=0    changed=0    unreachable=1    failed=0
        skipped=0    rescued=0    ignored=0   
    
    Friday 29 January 2021  09:23:35 +0100 (0:00:00.135)       0:00:00.158 ******** 
    ===============================================================================
    Gathering Facts --------------------------------------------------------- 0.14s
    Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds
    Ansible failed to complete successfully. Any error output should be
    visible above. Please fix these errors and try again.
    
    如何修复此错误?我并不特别需要 SSL,这只是在本地机器上测试虚拟机。

    最佳答案

    这让我发疯了。使用 host_key_checking 关闭 ssl 验证什么也没做,并且错误消息并不能完全引导您朝着正确的方向前进。 Openssl 报告两台机器都支持最高 1.3 的 tls。
    我了解到 official documentation建议使用 ssh 作为通信协议(protocol),并在 Windows 机器上设置 winrm。
    细节

  • 您很可能正在使用
    ansible_connection: winrm
    
    这是possibly outdated .相反,我能够与
    ansible_connection: ssh
    
  • 您可能已经这样做了,但如果没有,则需要在 Windows 主机上设置 WinRM。这方面的说明在这里,https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html#tls-1-2-support
  • winrm create 需要一个证书。对于设置自签名证书,由于 makecert 不再与 Windows10 捆绑在一起,因此我很幸运地使用了这些说明:https://woshub.com/how-to-create-self-signed-certificate-with-powershell .
  • 您已准备好运行 winrm create。在 cmd shell(不是 powershell)中
    winrm create winrm/config/listener?Address=IP:**your ipv6**+Transport=HTTPS @{HostName="**your host**";CertificateThumbprint="**your thumbprint**";Port="5986"}
    
  • 您将需要 Windows 机器的本地 IPv6 以避免冲突(通过 ipconfig /all 获得)
  • 从证书中提取主机名作为 CN(按照上述说明,您应该已经打开 certmgr.msc)
  • 指纹也在证书中



  • 为确保一切正常运行,您可以使用(从您的 ansible 机器)
    openssl s_client -connect **Windows box IP**:5986
    
    您不应收到“没有可用的对等证书”响应。
    注意:我没有尝试过信任来自我的 Linux 主机的自签名证书并使用 winrm 协议(protocol)。以上工作让我得到了我需要的东西。
    为了完整起见,我的库存:
     all:
       hosts:
         win_tower:
           ansible_host: **my IP**
           ansible_port: **my ssh port**
           ansible_user: **my ssh user**
           ansible_connection: ssh
           ansible_shell_type: cmd
           ansible_python_interpreter: C:\Git\usr\share\python\python-3.9.2x64\python
    

    关于ssl - Vagrant,Ansible : SSLError bad handshake: Error SSL routines, ssl3_get_record,错误的版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65951104/

    相关文章:

    docker - 使用 Ansible 部署 docker 时如何设置运行参数?

    ssh - 我怎么能用Ansible打开一个SSH外壳来远程控制?

    ruby-on-rails - Vagrant 文件重新同步 : Vagrant Box does not update new content in text editor

    ruby-on-rails - 如何在 Windows PC(Windows 7/Windows 8)上部署 Rails 应用程序?

    php - SSL 和非安全资源

    java - 如何设置 Apache Wink 客户端 keystore 和信任库

    ssl - cURL vs Postman,对 HTTPS POST 的不同响应

    python - JMESPath 日期过滤

    mysql - Laravel 家园 : Base table not found

    python - Pika/RabbitMq 套接字关闭通过 SSL 发送的大消息