【问题标题】:CircleCI job using Ansible : Exception: Error reading SSH protocol banner[Errno 104] Connection reset by peer使用 Ansible 的 CircleCI 作业:异常:读取 SSH 协议横幅时出错 [Errno 104] 连接由对等方重置
【发布时间】:2022-12-10 07:30:22
【问题描述】:

我正在处理在 EC2 实例上运行配置的 CircleCi 作业。问题是 ansible 无法运行配置并且仍然在这个循环中运行错误:

PLAY [configuration play]
******************************************************

TASK [wait 600 seconds for target connection to become reachable/usable] *******

Exception: Error reading SSH protocol banner[Errno 104] Connection reset by peer

Traceback (most recent call last):

File "/usr/lib/python3.8/site-packages/paramiko/transport.py", line 2211, in _check_banner

buf = self.packetizer.readline(timeout)

File "/usr/lib/python3.8/site-packages/paramiko/packet.py", line 380, in readline

buf += self._read_timeout(timeout)

File "/usr/lib/python3.8/site-packages/paramiko/packet.py", line 607, in _read_timeout

x = self.__socket.recv(128)

ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/lib/python3.8/site-packages/paramiko/transport.py", line 2039, in run

self._check_banner()

File "/usr/lib/python3.8/site-packages/paramiko/transport.py", line 2215, in _check_banner

raise SSHException(

paramiko.ssh_exception.SSHException: Error reading SSH protocol banner[Errno 104] Connection reset by peer

Exception: Error reading SSH protocol banner

Traceback (most recent call last):

File "/usr/lib/python3.8/site-packages/paramiko/transport.py", line 2211, in _check_banner

buf = self.packetizer.readline(timeout)

File "/usr/lib/python3.8/site-packages/paramiko/packet.py", line 380, in readline

buf += self._read_timeout(timeout)

File "/usr/lib/python3.8/site-packages/paramiko/packet.py", line 609, in _read_timeout

raise EOFError()

EOFError

....

fatal: [ec2-18-237-14-97.us-west-2.compute.amazonaws.com]: FAILED! => {"changed": false, "elapsed": 600, "msg": "timed out waiting for ping module test success: Error reading SSH protocol banner"}

PLAY RECAP *********************************************************************
ec2-18-237-14-97.us-west-2.compute.amazonaws.com : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

圈词工作:

  configure-infrastructure:
    docker:
      - image: python:3.7-alpine3.11
    steps:
      - checkout       
      - add_ssh_keys:
          fingerprints: ["bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla:bla"]
      - attach_workspace:
          at: ~/

      - run:
          name: Install dependencies
          command: |
              apk add --update tar gzip ansible
              pip install awscli
      - run:
          name: Configure server
          command: |
            cat ./.circleci/ansible/inventory.txt
            export ANSIBLE_HOST_KEY_CHECKING=False
            export RECORD_HOST_KEYS=True
            ansible-playbook -i ./.circleci/ansible/inventory.txt ./.circleci/ansible/configure-server.yml
      - destroy-environment

.circleci/ansible/configure-server.yml

---
- name: configuration play
  hosts: web
  user: ubuntu
  become: true
  become_method: sudo
  become_user: root
  gather_facts: false
  vars:
    - ansible_python_interpreter: /usr/bin/python3
    - ansible_host_key_checking: false
    - ansible_stdout_callback: yaml
  pre_tasks:
    - name: wait 600 seconds for target connection to become reachable/usable
      ansible.builtin.wait_for_connection:
        delay: 0
        timeout: 600
    - name: install python for Ansible.
      become: true
      raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3)
      changed_when: false
  roles: 
   - configure-server

角色/配置服务器/任务/main.yml

---
- name: "Update apt packages"
  become: true
  apt:
    update_cache: yes

- name: "Remove dependencies that are no longer required"
  become: true
  apt:
    autoremove: yes

- name: "Install npm and nodejs"
  become: true
  apt:
    name: ["npm", "nodejs"]
    state: latest
    update_cache: yes

- name: "Install pm2"
  become: true
  npm:
    name: pm2
    global: yes
    production: yes
    state: present

我已经将我的密钥对添加到 Circle 项目设置中,获取指纹并将其添加到作业配置中([bla:bla.....])。

我可以毫无问题地使用 ssh 连接到 Ec2 实例。

更多细节 :

ImageId: ami-0d70546e43a941d70 
region: us-west-2

任何帮助或建议将不胜感激。

【问题讨论】:

  • 你现在必须明白为什么你认为你可以通过 ssh 毫无问题地连接,而 Ansible 在从 circleci 基础设施运行时告诉你完全相反的情况(即connection reset by peer。在 ec2 端查看你的 sshd 日志可能会有所帮助。注意:这是off-topic 在 SO 上,尝试 serverfault.com

标签: amazon-ec2 ansible paramiko circleci


【解决方案1】:

它也困扰着我,最后我修好了:-

配置基础设施: 码头工人: # - 图片:python:3.7-alpine3.11 - 图片:蟒蛇:3.9.16

steps:
  - add_ssh_keys:
      fingerprints:
        - "6b:7d:b7:2c:5b:49:34:cb:34:ab:93:36:47:19:2b:73"
  - run:
      name: Install dependenciess
      command: |
        # apk add --update ansible 
        apt-get update -y
        apt install ansible -y
        which ansible
  - run:
      name: Configure server
      command: |
        cd .circleci/ansible
        cat ./inventory
        ansible-playbook -i inventory configure-server.yml

【讨论】:

    猜你喜欢
    • 2022-08-07
    • 2014-10-25
    • 1970-01-01
    • 2011-11-04
    • 2017-10-05
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多