質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
公開鍵認証

公開鍵認証とは、公開鍵と秘密鍵の2つの鍵の組を利用する、SSHで利用される認証方式です。

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

パスワード

パスワードは主に情報にアクセスする際に扱われます。主に、アクセス可能なユーザーを限定する手段として使われます。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

Q&A

1回答

4023閲覧

ansibleで踏み台を経由したSSH接続ができません

tiqua_nibio

総合スコア62

公開鍵認証

公開鍵認証とは、公開鍵と秘密鍵の2つの鍵の組を利用する、SSHで利用される認証方式です。

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

パスワード

パスワードは主に情報にアクセスする際に扱われます。主に、アクセス可能なユーザーを限定する手段として使われます。

Ansible

Ansibleは、Python で書かれたサーバーの設定を管理するための 構成管理ツールです。

0グッド

0クリップ

投稿2020/10/14 04:56

編集2020/10/14 05:27

まず、ansibleで使うssh_configファイルは以下のようになっております。/etc/ansibleディレクトリに作成しました。ローカルからは、pathwayマシン、destinationマシンどちらにも直接ssh接続することは可能なようです。ただ、あえてpathwayを踏み台として使っております。

locak -> pathway -> destination by SSH connection

ssh_config

1Host pathway 2 HostName 102.211.66.66 3 Port 5522 4 User guardian 5 PasswordAuthentication no 6 IdentityFile ~/.ssh/id_ecdsa 7 8Host destination 9 HostName 102.211.66.100 10 Port 5522 11 User tanto 12 IdentitiesOnly yes 13 PasswordAuthentication yes 14 ProxyCommand ssh -F ssh_config -W %h:%p pathway 15 16

これらの設定はssh接続をする上で正常に働いているようです。

[root@localhost ansible]# ssh -F /etc/ansible/ssh_config pathway Enter passphrase for key '/root/.ssh/id_ecdsa': Last login: Wed Oct 14 13:36:34 2020 from (省略) [root@localhost ansible]# ssh -F /etc/ansible/ssh_config destination tanto@102.211.66.100's password: Last login: Wed Oct 14 13:14:58 2020 from (省略)

hostsインベントリファイルです。

[remote2] destination

踏み台であるpathwayへ飛ぶときは、公開鍵認証で、そこからdestinationへ飛ぶときはパスワード認証を求められます。
これが原因なのかどうかわかりませんが、接続失敗します。公開鍵認証で正しくパスフレーズはアクセプトされているようですが。

bash

1[root@localhost ansible]# ansible all -m ping -i hosts 2Enter passphrase for key '/root/.ssh/id_ecdsa': 3destination | UNREACHABLE! => { 4 "changed": false, 5 "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\nKilled by signal 1.", 6 "unreachable": true 7} 8

最後にansible.cfgファイルです。

[ssh_connection] control_path = %(directory)s/%%h-%%r ssh_args = -o ControlPersist=15m -F ssh_config -q scp_if_ssh = True

もし変なところがありましたら、指摘いただけますと幸いです。よろしくお願いいたします。
詳細エラーについて、追加いたします。

[root@localhost ansible]# ansible all -m ping -i hosts -vvvvv ansible 2.9.13 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, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] Using /etc/ansible/ansible.cfg as config file setting up inventory plugins host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method Parsed /etc/ansible/hosts inventory source with ini plugin Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/minimal.pyc META: ran handlers <destination> ESTABLISH SSH CONNECTION FOR USER: None <destination> SSH: ansible.cfg set ssh_args: (-o)(ControlPersist=15m)(-F)(/etc/ansible/ssh_config)(-q) <destination> SSH: ansible_password/ansible_ssh_password not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no) <destination> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) <destination> SSH: PlayContext set ssh_common_args: () <destination> SSH: PlayContext set ssh_extra_args: () <destination> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/root/.ansible/cp/%h-%r) <destination> SSH: EXEC ssh -vvv -o ControlPersist=15m -F /etc/ansible/ssh_config -q -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/%h-%r destination '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' Enter passphrase for key '/root/.ssh/id_ecdsa': <destination> (255, '', 'Killed by signal 1.\r\n') destination | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Killed by signal 1.", "unreachable": true }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ssh_args = -o ControlPersist=15m -F ssh_config -q

これを

ssh_args = -o ControlPersist=15m -F /etc/ansible/ssh_config -q

とするのはいかがでしょう。

ansible all -m ping -i hosts -vvvv
で実行すると何かわかるかもしれません。

投稿2020/10/14 05:12

SugiTK

総合スコア495

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tiqua_nibio

2020/10/14 05:29

ssh_args = -o ControlPersist=15m -F /etc/ansible/ssh_config -q 残念ながらこれは解決にはなりませんでした。 詳細エラーについて、質問に追加いたしました。 PasswordAuthがnoになっているのが気になりますが。
SugiTK

2020/10/14 10:28

destination では password が要るというのを見落としていました。 ansible all -m ping -i hosts -vvvv --ask-pass ではいかがでしょう。
tiqua_nibio

2020/10/19 09:08

コメントに気づかず、申し訳ありません。 仰る方法でうまくできませんでした。 Enter passphraseの代わりにSSH password:というメッセージが出て、パスワードを入力しましたが、本来はEnter passphraseが先ですね。
SugiTK

2020/10/19 09:16

となると ssh-agent 使って先に passphrase を解決してから ansible-playbook を実行することになりそうです。 なかなかすっきり解決できずすみません。
tiqua_nibio

2020/10/19 10:06

いえ、ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問