원격 호스트에서 ansible로 여러 셸 명령을 실행하려고 하는데 비참하게 실패합니다.
- name: Mkdir on server and copy packages locally
shell: |
mkdir /root/vdbench
cd /root
cp vdbench50403.zip /root/vdbench
cd /root/vdbench
unzip vdbench50403.zip
실수:
TASK [Mkdir on server and copy packages locally] *******************************
fatal: [153.254.108.166]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006011", "end": "2017-05-26 07:24:30.518445", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.512434", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.165]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.005799", "end": "2017-05-26 07:24:30.740551", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.734752", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.164]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006032", "end": "2017-05-26 07:24:30.745565", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.739533", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
fatal: [153.254.108.163]: FAILED! => {"changed": true, "cmd": "mkdir /root/vdbench\n cd /root\n cp vdbench50403.zip /root/vdbench\n cd /root/vdbench\n unzip vdbench50403.zip", "delta": "0:00:00.006703", "end": "2017-05-26 07:24:30.832733", "failed": true, "rc": 127, "start": "2017-05-26 07:24:30.826030", "stderr": "mkdir: cannot create directory ‘/root/vdbench’: File exists\n/bin/sh: line 4: unzip: command not found", "stdout": "", "stdout_lines": [], "warnings": ["Consider using file module with state=directory rather than running mkdir"]}
답변1
출력 내용을 읽어보십시오.
- 디렉터리가 이미 존재하기 때문에 mkdir이 실패했습니다.
- 대상 시스템에 unzip 명령이 없습니다.
오류를 수정하려면 다음을 수행하십시오.
- -p 플래그를 mkdir에 전달
- 대상 서버에 unzip 설치
또는 더 나은 방법은 대상 호스트에서 쉘 명령을 실행하는 대신 ansible 모듈을 사용하여 작업을 수행하도록 플레이북을 변경하는 것입니다.
- name: Extract vdbench
unarchive:
src: vdbench50403.zip
dest: /root/vdbench
src는 Ansible을 실행 중인 컴퓨터의 파일입니다.