簡體   English   中英

Ansible EC2 沒有這樣的文件或目錄:b'ssh':b'ssh'

[英]Ansible EC2 No such file or directory: b'ssh': b'ssh'

我正在嘗試將 dockerized react web 應用程序部署到 EC2,但在配置實例時仍然出現錯誤。 已經搜索但沒有找到任何東西。

使用命令部署:

ansible-playbook -vvvvv ansible/ec2_deploy.yml --user ubuntu

Docker 我正在運行 ansible :

FROM node:10.23.0-alpine3.9
COPY . .
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add --update ansible
RUN apk add 
RUN pip install boto
RUN chmod 777 get_vault_pass.sh
ENTRYPOINT [ "/bin/sh" ]

Ansible部署:

- name: Deploy to EC2
  hosts: localhost
  connection: local

  tasks:
    - name: Launch EC2 instance
      ec2:
        instance_type: t2.micro
        image: ami-0885b1f6bd170450c
        region: us-east-1
        key_name: eshop-key-pair
        vpc_subnet_id: subnet-cafc34fb
        assign_public_ip: yes
        wait: yes
        count: 1
        group: eshop
        aws_access_key: 'key'
        aws_secret_key: 'key2'
        security_token: 'token'
      register: ec2

    - name: Add instance host to group
      add_host: hostname={{ item.public_dns_name }} groupname=launched
      with_items: '{{ec2.instances}}'

    - name: Wait for SSH connection
      wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=600 state=started
      with_items: '{{ec2.instances}}'

- name: Configure EC2
  hosts: launched
  connection: ssh

  tasks:
    - name: Install docker
      apt:
        name: docker.io
        state: present
        update_cache: yes
      become: yes
    - service:
        name: docker
        state: started
        enabled: yes
      become: yes
    - name: Get project files from GIT
      git: 
        repo: 'https://github.com/romanzdk/4IT572_ZS_2020_circleci.git'
        dest: ./app
    - name: Build docker with eshop
      shell: cd app && docker build -t myeshop:latest .
      become: yes
    - name: Run docker with eshop
      shell: docker run -p 80:3000 myeshop
      async: 90
      poll: 15
      become: yes
    - wait_for: delay=60 timeout=600
      port: 80

堆棧跟蹤:


PLAY [Configure EC2] ***********************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************
task path: /ansible/ec2_deploy.yml:30
<ec2-100-25-28-7.compute-1.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: None
<ec2-100-25-28-7.compute-1.amazonaws.com> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<ec2-100-25-28-7.compute-1.amazonaws.com> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<ec2-100-25-28-7.compute-1.amazonaws.com> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)
<ec2-100-25-28-7.compute-1.amazonaws.com> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/root/.ansible/cp/aaee2dc684)
<ec2-100-25-28-7.compute-1.amazonaws.com> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/aaee2dc684 ec2-100-25-28-7.compute-1.amazonaws.com '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/ansible/executor/task_executor.py", line 140, in run
    res = self._execute()
  File "/usr/lib/python3.6/site-packages/ansible/executor/task_executor.py", line 612, in _execute
    result = self._handler.run(task_vars=variables)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/action/normal.py", line 46, in run
    result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
  File "/usr/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 745, in _execute_module
    self._make_tmp_path()
  File "/usr/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 294, in _make_tmp_path
    tmpdir = self._remote_expand_user(tmpdir, sudoable=False)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 613, in _remote_expand_user
    data = self._low_level_execute_command(cmd, sudoable=False)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/action/__init__.py", line 980, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/connection/ssh.py", line 1145, in exec_command
    (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/connection/ssh.py", line 392, in wrapped
    return_tuple = func(self, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/connection/ssh.py", line 1035, in _run
    return self._bare_run(cmd, in_data, sudoable=sudoable, checkrc=checkrc)
  File "/usr/lib/python3.6/site-packages/ansible/plugins/connection/ssh.py", line 790, in _bare_run
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: b'ssh': b'ssh'

fatal: [ec2-52-73-248-179.compute-1.amazonaws.com]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

知道有什么問題嗎? 我已經在這上面花了很長時間......這里還有一些文字,因為我被要求添加更多細節,因為代碼很長,哈哈

chepner 的評論是正確的 - 您的 docker 圖像沒有安裝ssh 嘗試

apk add openssh-client

並且應該解決錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM