본문 바로가기
인프라/앤서블(Ansible)

[ansible] The error was: ImportError: No module named pexpect

by IT맥구리나스 2022. 5. 31.

코드

#!/bin/bash
echo "Press 'y' to confirm ('s' to skip, 'a' to abort):"
read response
echo $response

플레이북

---
- hosts: localhost
  tasks:
    - name: "Execute app"
      expect:
        command: /home/jenkins/test.sh
        responses:
          Press 'y' to confirm \('s' to skip\, 'a' to abort\):: "y"
        echo: yes

 

에러내용

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pexpect
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pexpect) on seo-node00-centos's Python /usr/bin/python2. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

 

해결방법

pip install pexpect

 

설치를 했는데 아래와 같은 오류가 보일수 있다. 

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

다음과 같이 처리한다.

python -m pip install pexpect

 

반응형

댓글