
첫 번째 플레이북을 실행하려고 합니다. CentOS8에서 AWX를 실행하고 SSH를 사용하여 원격 장치에 연결을 시도합니다. 내 원격 장치에서 내 장치에서 ssh-genkey를 실행하고 .pub 키를authorized_keys 파일에 추가했습니다. 또한 .pub 개인 키를 가져와서 자격 증명 머신 유형을 생성하고 개인 키를 추가했습니다. 사용자 이름과 비밀번호가 비어 있습니다. 내 원격 장치에는 루트 사용자를 통해서만 연결할 수 있습니다. 여기에 이미지 설명을 입력하세요.
내 플레이북은 다음과 같습니다.
- name: use machine credentials(1)
hosts: ACS
connection: ssh
gather_facts: false
timeout: 10
tasks:
- name: Get firmware version from host
shell: "date"
#shell: cat /firmware | grep ^VERSION | cut -d"=" -f2
register: firmware_version
tags: firmware_version
원격 장치에 SSH를 통해 연결하고 원격 장치의 파일에서 펌웨어 세부 정보를 읽으려고 합니다.
플레이북을 실행하면 출력이 실패하고 원격 장치에 연결되어 있는 것 같지 않습니다. Putty 세션을 통해 AWX 호스트에서 원격 장치로 수동으로 SSH를 수행할 수 있습니다. AWX 호스트에서 개인 키 파일을 사용해 보았고 Putty의 키를 사용하여 원격 장치에 SSH로 연결할 수 있습니다.
AWX의 출력:
Identity added: /runner/artifacts/196/ssh_key_data (/runner/artifacts/196/ssh_key_data)
ansible-playbook [core 2.14.2]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /runner/requirements_collections:/home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.16 (main, Dec 8 2022, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
host_list declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
Parsed /runner/inventory/hosts inventory source with script plugin
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: acs_backup.yml *******************************************************
1 plays in acs_backup.yml
PLAY [use machine credentials(1)] **********************************************
TASK [Get firmware version from host] ******************************************
task path: /runner/project/acs_backup.yml:18
<10.162.29.138> ESTABLISH SSH CONNECTION FOR USER: root
<10.162.29.138> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/runner/cp/4477df8717"' 10.162.29.138 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<10.162.29.138> (0, b'/home/root\\r\\n', b"Warning: Permanently added '10.162.29.138' (ED25519) to the list of known hosts.\\r\\n")
<10.162.29.138> ESTABLISH SSH CONNECTION FOR USER: root
<10.162.29.138> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/runner/cp/4477df8717"' 10.162.29.138 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/root/.ansible/tmp `"&& mkdir "` echo /home/root/.ansible/tmp/ansible-tmp-1677124576.2755764-27-69248210230276 `" && echo ansible-tmp-1677124576.2755764-27-69248210230276="` echo /home/root/.ansible/tmp/ansible-tmp-1677124576.2755764-27-69248210230276 `" ) && sleep 0'"'"''
<10.162.29.138> (0, b'ansible-tmp-1677124576.2755764-27-69248210230276=/home/root/.ansible/tmp/ansible-tmp-1677124576.2755764-27-69248210230276\\r\\n', b'')
<ACS-10.162.29.138> Attempting python interpreter discovery
<10.162.29.138> ESTABLISH SSH CONNECTION FOR USER: root
<10.162.29.138> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/runner/cp/4477df8717"' 10.162.29.138 '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.11'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<10.162.29.138> (0, b'PLATFORM\\r\\nLinux\\r\\nFOUND\\r\\n/usr/bin/python3.5\\r\\n/usr/bin/python3\\r\\n/usr/bin/python2.7\\r\\n/usr/bin/python\\r\\n/usr/bin/python\\r\\nENDFOUND\\r\\n', b'')
<10.162.29.138> ESTABLISH SSH CONNECTION FOR USER: root
<10.162.29.138> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/runner/cp/4477df8717"' 10.162.29.138 '/bin/sh -c '"'"'/usr/bin/python3.5 && sleep 0'"'"''
fatal: [ACS-10.162.29.138]: FAILED! => {
"changed": false,
"msg": "The shell action failed to execute in the expected time frame (10) and was terminated"
}
PLAY RECAP *********************************************************************
ACS-10.162.29.138 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
SSH를 통해 원격 장치에 연결되지 않는 이유에 대해 누구든지 올바른 방향을 알려줄 수 있습니까?
답변1
SSH를 통해 연결하는 데 문제가 있습니다.
10.162.29.138은 비공개 주소입니다. VPC의 머신에서 ansible 스크립트를 실행하고 있습니까? 그렇지 않다면 그건 바로첫 번째 문제당신은 해결해야합니다.
동일한 VPC에 있거나 서브넷에 대한 터널이 있는 경우 실행을 시도하고 nc -zv 10.162.29.138 22
연결되면 ansible 스크립트를 다시 시도하십시오. 그래도 실패한다면같은 이유로ssh -vv ....
, 그런 다음 nc 및 ssh 명령의 출력을 설명하는 명령줄에서 connectnig를 사용해 보십시오 .
답변2
GITHUB에 연결하고 로컬 AWX 호스트에서 프로젝트를 동기화 중입니다. AWX와 SSH를 통해 연결하려는 장치는 모두 동일한 로컬 네트워크 10.162.29.x에 있습니다.
나는 당신의 명령을 실행했습니다. NCAP 및 ssh를 사용하여 연결할 수 있지만 ssh의 상세 모드에서는 "10.162.29.138 [10.162.29.138] 포트 22에 연결하는 중이므로 그 이유가 확실하지 않고 연결이 완료되지 않습니다."라는 메시지만 계속 표시됩니다.
[localadmin@centOS8-awx ~]$ nc -zv 10.162.29.138 22 Ncat: 버전 7.70 (https://nmap.org/ncat) Ncat: 10.162.29.138:22에 연결됩니다. Ncat: 0.01초 안에 0바이트가 전송되고 0바이트가 수신되었습니다.
[localadmin@centOS8-awx ~]$ SSH[이메일 보호됨] 비밀번호:
경고: 쉘 명령을 부적절하게 사용하면 데이터 손실, 중요한 시스템 파일 삭제 또는 기타 예상치 못한 결과가 발생할 수 있습니다. 쉘 명령을 입력할 때 구문을 다시 확인하십시오.
[root@ACS8008-0520414440 ~]# 10.162.29.138에 대한 종료 연결이 닫혔습니다.
[localadmin@centOS8-awx ~]$ ssh -vv[이메일 보호됨] OpenSSH_8.0p1, OpenSSL 1.1.1k FIPS 2021년 3월 25일 debug1: 구성 데이터 읽기 /etc/ssh/ssh_config debug1: 구성 데이터 읽기 /etc/ssh/ssh_config.d/05-redhat.conf debug2: 'final all에 대한 일치 확인 ' 호스트 10.162.28.138 원래 10.162.28.138 debug2: 일치 항목을 찾을 수 없음 debug1: 구성 데이터 읽기 /etc/crypto-policies/back-ends/openssh.config debug1: 구성이 최종 일치 패스를 요청합니다. debug2:solv_canonicalize: 호스트 이름 10.162.28.138은 주소입니다. debug1: 구성 재분석 debug1: 구성 데이터 읽기 /etc/ssh/ssh_config debug1: 구성 데이터 읽기 /etc/ssh/ssh_config.d/05-redhat.conf debug2: 원래 '최종 전체' 호스트 10.162.28.138에 대한 일치 확인 10.162.28.138 debug2: 일치 항목 발견 debug1: 구성 데이터 /etc/crypto-policies/back-ends/openssh.config 읽기 debug2: ssh_connect_direct debug1: 10.162.28.138 [10.162.28.138] 포트 22에 연결 중.