
最初のプレイブックを実行しようとしています。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 コマンドの出力を記述したコマンド ラインでを使用して接続を試みます。
答え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 ~]# exit10.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: 設定が final 一致を要求しています debug2: resolve_canonicalize: ホスト名 10.162.28.138 はアドレスです debug1: 設定を再解析しています 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 を読み込んでいます。debug2: ssh_connect_direct debug1: 10.162.28.138 [10.162.28.138] ポート 22 に接続しています。