![Ansible 모듈 Expect를 사용하면 다음 메시지가 나타납니다: The pexpect Python 모듈이 필요합니다.](https://linux55.com/image/136414/Ansible%20%EB%AA%A8%EB%93%88%20Expect%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%A9%B4%20%EB%8B%A4%EC%9D%8C%20%EB%A9%94%EC%8B%9C%EC%A7%80%EA%B0%80%20%EB%82%98%ED%83%80%EB%82%A9%EB%8B%88%EB%8B%A4%3A%20The%20pexpect%20Python%20%EB%AA%A8%EB%93%88%EC%9D%B4%20%ED%95%84%EC%9A%94%ED%95%A9%EB%8B%88%EB%8B%A4..png)
yml 파일의 일부 코드:
- name: --- run /opt/installer/bin/install.sh ---
expect:
command: /opt/installer/bin/install.sh
responses:
'Are you installing the application at the central data center? [yes/no default: yes]? [yes]': "\n"
'What is the code of central data center [default: 01]? [01]': "\n"
'What is ip or hostname of your server [default: localhost]? [localhost]': 'portal'
pexpect 3.3
두 서버( ansible
및 대상 ) 모두 machines
에 모듈을 설치했습니다 .
[root@portal pexpect-3.3]# python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
Writing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
플레이북을 실행하면 다음 오류가 발생합니다.
TASK [ansible-portal : --- run /opt/installer/bin/install.sh ---] *************************************************************************
fatal: [portal]: FAILED! => {"changed": false, "msg": "The pexpect python module is required"}
추가 정보:
[root@ansible ansible]# ansible --version
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
답변1
이러한 모듈 중 일부와 마찬가지로 ansible
원격 서버 측에 설치해야 하는 특정 Python 모듈이 있습니다.
이 모듈을 사용하면 다음과 같이 플레이북을 pip
통해 ansible
이를 촉진할 수 있습니다.
- name: install pexpect
pip:
name: pexpect
become: yes
배포판에서는 이러한 파일을 DEB 또는 RPM 파일로 제공할 수도 있습니다. 그렇다면 배포판의 패키지 관리자를 사용하여 이 Python 모듈을 설치할 수 있습니다.
귀하의 경우, 모듈을 설치한 Python이 pexpect
사용 중인 Python과 다를 수 있습니다 ansible
. 이 경우 시스템의 패키지 관리자를 사용하여 설치합니다 pexpect
.
패키지 관리자를 통해
Debian/Ubuntu 시스템에서 apt-get 사용:
$ sudo apt-get install python-pexpect
Redhat 배포판(Fedora/CentOS):
$ sudo yum install -y pexpect