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

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

新規登録して質問してみよう
ただいま回答率
85.48%
CentOS

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

SSH

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

Ansible

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

Q&A

解決済

1回答

9554閲覧

Ansible playbook実行時のsshエラー

papachiropa

総合スコア14

CentOS

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

SSH

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

Ansible

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

0グッド

0クリップ

投稿2020/06/01 08:39

編集2020/06/02 07:14

サーバA(192.168.100.251)とB(192.168.100.253)に対して
Ansible playbookを実行すると下記のようなエラーが出ます。(Ansible操作端末も対象サーバもCentOS7です)

[root@hoge tmp]# ansible-playbook OracleJDK.yml -i hosts PLAY ***************************************************************************************************************************** TASK [create target dir.] ***************************************************************************************************************** Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': ok: [192.168.100.251] fatal: [192.168.100.253]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true}

サーバAは成功しますが、Bは失敗します。上記エラーの解消方法をご教示頂けたらと思います。

また、下記サイトの通りにansible all -m ping -i hostsを
実行してみるとエラーが出たので、ssh-copy-idコマンドで対象サーバーに公開鍵を設置してみましたが
ansible all -m ping -i hostsの結果が都度変わるような状況です。(下のパターン⓵と⓶参照)

ansible で UNREACHABLE! Failed to connect to the host via ssh: Permission denied エラーで対象ホストにログインできない

#⓵ [root@hoge tmp]# ansible all -m ping -i hosts Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': 192.168.100.251 | SUCCESS => { "changed": false, "ping": "pong" } 192.168.100.253 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true #⓶ [root@hoge tmp]# ansible all -m ping -i hosts Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': 192.168.100.253 | SUCCESS => { "changed": false, "ping": "pong" } 192.168.100.251 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true }

端折って申し訳ございません。実行予定のplaybookは下記です。

YAML

1- hosts: tomcat 2 vars: 3  ansible_user: root 4  ansible_ssh_private_key_file: /root/.ssh/id_rsa 5 gather_facts: no 6 remote_user: root 7 become: true 8 tasks: 9 - name: create target dir. 10 file: path=/root/soft state=directory 11 - copy: 12 src=/tmp/jdk-8u202-linux-x64.rpm 13 dest=/root/soft/jdk-8u202-linux-x64.rpm 14 owner=root 15 group=root 16 mode=0644 17 - name: install JDK 14 from a local file 18 yum: name=/root/soft/jdk-8u202-linux-x64.rpm state=present

6/2時点エラー状況

[root@hoge tmp]# ansible-playbook OracleJDK.yml -i hosts PLAY [tomcat] ************************************************************************************************************************************ TASK [create target dir.] ************************************************************************************************************************ Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': ok: [linux3] fatal: [linux1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true} TASK [copy] ************************************************************************************************************************************** ok: [linux3] TASK [install JDK 14 from a local file] ********************************************************************************************************** ok: [linux3] to retry, use: --limit @/tmp/OracleJDK.retry PLAY RECAP *************************************************************************************************************************************** linux1 : ok=0 changed=0 unreachable=1 failed=0 linux3 : ok=3 changed=0 unreachable=0 failed=0

宜しくお願い致します。

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

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

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

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

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

guest

回答1

0

ベストアンサー

二つのホストは同じssh鍵を使用していますか?
ansible使わずにsshコマンドで接続できますか?

投稿2020/06/01 08:56

comefigo

総合スコア1045

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

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

papachiropa

2020/06/01 10:15

度々すみません。 >二つのホストは同じssh鍵を使用していますか? はい、両方とも操作端末から配布された鍵を使っております。 >ansible使わずにsshコマンドで接続できますか? はい、下記コマンドそれぞれ成功します。 ssh root@192.168.100.251 ssh root@192.168.100.253
comefigo

2020/06/01 10:23

いえいえ。 ansible側のssh鍵の指定とパスワード指定はどこでどのようにしていますか?(パスワードはマスキングして頂いてOKです) 例えばインベントリファイルで指定しているとか。
comefigo

2020/06/01 13:59

スライドのp.9のようにAnsibleの実行元にある公開鍵(/root/.ssh/id_rsa.pub)と対象の公開鍵(~/.ssh/authorized_keys)は同じでしょうか? あと前の回答でSSHコマンド(-i 秘密鍵を指定していない)でつながったとのことですが、ssh configを設定されているのでしょうか?
papachiropa

2020/06/02 00:08

>スライドのp.9のようにAnsibleの実行元にある公開鍵(/root/.ssh/id_rsa.pub)と対象の公開鍵(~/.ssh/authorized_keys)は同じでしょうか? はい、同じでした。それぞれcatで確認しました。 >ssh configを設定されているのでしょうか? 下記の様に設定されております。 [root@hoge ~]# cat /root/.ssh/ssh_config Host linux1 HostName 192.168.100.251 User root Host linux2 HostName 192.168.100.252 User root Host linux3 HostName 192.168.100.253 User root
comefigo

2020/06/02 04:29 編集

なるほど。ssh_configで接続ユーザ指定しているのですね。 ssh鍵を明示的に指定していないので、明示的にしてはいかがでしょうか? それがダメでしたら、playbook側で以下の様(ansible_user、ansible_ssh_private_key_file)に指定してみてください。 - name: Playbook  hosts: centos  vars:   ansible_user: root   ansible_ssh_private_key_file: /root/.ssh/id_rsa  tasks:   省略
papachiropa

2020/06/02 05:53

ありがとうございます。 >ssh鍵を明示的に指定していないので、明示的にしてはいかがでしょうか? 下記のようなイメージで宜しいでしょうか? [root@hoge tmp]# cat /root/.ssh/ssh_config Host linux1 HostName 192.168.100.251 User root PubkeyAuthentication yes IdentityFile /root/.ssh/id_rsa Host linux2 HostName 192.168.100.252 User root PubkeyAuthentication yes IdentityFile /root/.ssh/id_rsa Host linux3 HostName 192.168.100.253 User root PubkeyAuthentication yes IdentityFile /root/.ssh/id_rsa ただ、これでplaybookを実行しましたが同じエラーが出ました。 >playbook側で以下の様(ansible_user、ansible_ssh_private_key_file)に指定してみてください。 追記しました。上の様に書いてみたのですがシンタックスエラーが出まして… 色々インデントをズラしてみたりしてみたのですが動きません。 お手数ですがご指摘宜しくお願い致します。 また、ssh接続はIPアドレスだとどれも成功するのですが ホスト名だとlinux2は成功してlinux1,3は失敗します(いずれもssh configに記載済) これは今回のエラーには関係ないものでしょうか?
comefigo

2020/06/02 06:10 編集

playbookのシンタックスエラーはおそらくスペースが全角になっていると思われます(前の回答で記載したサンプルコードで半角空白だとエスケープされるので、全角で記載しました) hostsファイルはどのようになっていますか?
papachiropa

2020/06/02 06:25

シンタックスエラー失礼しました。半角に直したら解消されました。 hostsは下記です。 [root@hoge tmp]# cat hosts [tomcat] 192.168.100.251 192.168.100.253 [not] 192.168.100.252
comefigo

2020/06/02 06:59 編集

半角空白修正後はいかがでしょうか? > ホスト名だとlinux2は成功してlinux1,3は失敗します hostsファイルにホスト名で指定することでしょうか? [tomcat] linux1 linux3
papachiropa

2020/06/02 07:18

半角修正とhostsにホスト名の追記を実施したうえでplaybookを実行した結果を追記しました。 やはり同じエラーが出ます。また、ssh接続に関してですがやはり「ssh linux1」と「ssh linux3」のみうまくいきませんでした。「ssh: Could not resolve hostname linux1: Name or service not known」というエラーが出ます。
comefigo

2020/06/02 08:49

hostsにはホスト名ではなくipで記載してほしいですね。 前述の回答はサンプルとしてこのように記述しているのでしょうか?という意図で書いたものです。
papachiropa

2020/06/03 00:27

[tomcat] linux1 ansible_host=192.168.100.251 linux3 ansible_host=192.168.100.253 [not] linux2 ansible_host=192.168.100.252 もともとhostsは上記の様にしておりましたが、 IPだけの状態に戻しました。 現在は [root@hoge tmp]# cat hosts [tomcat] 192.168.100.251 192.168.100.253 [not] 192.168.100.252 です。しかしplaybookを実行しても192.168.100.253に関してはUNREACHABLE!のままです。
comefigo

2020/06/03 03:43

ansible-playbookコマンドの最後に-vvvを追加して、エラー時のデバックログを教えていただけますか?
papachiropa

2020/06/03 04:28

承知しました。文字数の都合があるので分けて貼ります。
papachiropa

2020/06/03 04:29

[root@hoge tmp]# ansible-playbook OracleJDK.yml -i hosts -vvv ansible-playbook 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-playbook python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] Using /etc/ansible/ansible.cfg as config file Parsed /tmp/hosts inventory source with ini plugin PLAYBOOK: OracleJDK.yml ********************************************************************************************************************* 1 plays in OracleJDK.yml PLAY [tomcat] ******************************************************************************************************************************* META: ran handlers TASK [create target dir.] ******************************************************************************************************************* task path: /tmp/OracleJDK.yml:6 Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/file.py <192.168.100.251> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.251> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ee0c878148 192.168.100.251 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/file.py <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' Enter passphrase for key '/root/.ssh/id_rsa': Enter passphrase for key '/root/.ssh/id_rsa': <192.168.100.253> (0, '/root\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429 `" && echo ansible-tmp-1591157255.21-155980626092429="` echo /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429 `" ) && sleep 0'"'"'' <192.168.100.253> (0, 'ansible-tmp-1591157255.21-155980626092429=/root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429\n', '') <192.168.100.253> PUT /tmp/tmpOPNr4Y TO /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/file.py <192.168.100.253> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 '[192.168.100.253]' <192.168.100.253> (0, 'sftp> put /tmp/tmpOPNr4Y /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/file.py\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/ /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/file.py && sleep 0'"'"'' <192.168.100.253> (0, '', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 -tt 192.168.100.253 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/file.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1591157255.21-155980626092429/" > /dev/null 2>&1 && sleep 0'"'"'' <192.168.100.253> (0, '\r\n{"group": "root", "uid": 0, "changed": false, "owner": "root", "state": "directory", "gid": 0, "secontext": "unconfined_u:object_r:admin_home_t:s0", "mode": "0755", "path": "/root/soft", "invocation": {"module_args": {"directory_mode": null, "force": false, "remote_src": null, "path": "/root/soft", "owner": null, "follow": false, "group": null, "unsafe_writes": null, "state": "directory", "content": null, "serole": null, "diff_peek": null, "setype": null, "selevel": null, "original_basename": null, "regexp": null, "validate": null, "src": null, "seuser": null, "recurse": false, "delimiter": null, "mode": null, "attributes": null, "backup": null}}, "diff": {"after": {"path": "/root/soft"}, "before": {"path": "/root/soft"}}, "size": 37}\r\n', 'Shared connection to 192.168.100.253 closed.\r\n')
papachiropa

2020/06/03 04:30

ok: [192.168.100.253] => { "changed": false, "diff": { "after": { "path": "/root/soft" }, "before": { "path": "/root/soft" } }, "gid": 0, "group": "root", "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "delimiter": null, "diff_peek": null, "directory_mode": null, "follow": false, "force": false, "group": null, "mode": null, "original_basename": null, "owner": null, "path": "/root/soft", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "directory", "unsafe_writes": null, "validate": null } }, "mode": "0755", "owner": "root", "path": "/root/soft", "secontext": "unconfined_u:object_r:admin_home_t:s0", "size": 37, "state": "directory", "uid": 0 } <192.168.100.251> (255, '', 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n') fatal: [192.168.100.251]: UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", "unreachable": true }
papachiropa

2020/06/03 04:30

TASK [copy] ********************************************************************************************************************************* task path: /tmp/OracleJDK.yml:8 <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' <192.168.100.253> (0, '/root\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392 `" && echo ansible-tmp-1591157268.1-94807853603392="` echo /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392 `" ) && sleep 0'"'"'' <192.168.100.253> (0, 'ansible-tmp-1591157268.1-94807853603392=/root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392\n', '') Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/stat.py <192.168.100.253> PUT /tmp/tmpn0CNx1 TO /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/stat.py <192.168.100.253> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 '[192.168.100.253]' <192.168.100.253> (0, 'sftp> put /tmp/tmpn0CNx1 /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/stat.py\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/ /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/stat.py && sleep 0'"'"'' <192.168.100.253> (0, '', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 -tt 192.168.100.253 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/stat.py && sleep 0'"'"'' <192.168.100.253> (0, '\r\n{"invocation": {"module_args": {"checksum_algorithm": "sha1", "get_checksum": true, "path": "/root/soft/jdk-8u202-linux-x64.rpm", "checksum_algo": "sha1", "follow": false, "get_md5": false, "get_mime": true, "get_attributes": true}}, "stat": {"charset": "binary", "uid": 0, "exists": true, "attr_flags": "", "woth": false, "isreg": true, "device_type": 0, "mtime": 1590983610.7846944, "block_size": 4096, "inode": 100912366, "isgid": false, "size": 178418154, "executable": false, "isuid": false, "readable": true, "version": "1766401508", "pw_name": "root", "gid": 0, "ischr": false, "wusr": true, "writeable": true, "mimetype": "application/x-rpm", "blocks": 348480, "xoth": false, "islnk": false, "nlink": 1, "issock": false, "rgrp": true, "gr_name": "root", "path": "/root/soft/jdk-8u202-linux-x64.rpm", "xusr": false, "atime": 1591081644.2368343, "isdir": false, "ctime": 1590983612.15769, "isblk": false, "wgrp": false, "checksum": "565f4ea1526cb88b4251a3e4982f3bcc16112a01", "dev": 64768, "roth": true, "isfifo": false, "mode": "0644", "xgrp": false, "rusr": true, "attributes": []}, "changed": false}\r\n', 'Shared connection to 192.168.100.253 closed.\r\n') Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/file.py <192.168.100.253> PUT /tmp/tmpUygiDg TO /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/file.py <192.168.100.253> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 '[192.168.100.253]' <192.168.100.253> (0, 'sftp> put /tmp/tmpUygiDg /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/file.py\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/ /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/file.py && sleep 0'"'"'' <192.168.100.253> (0, '', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 -tt 192.168.100.253 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/file.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1591157268.1-94807853603392/" > /dev/null 2>&1 && sleep 0'"'"'' <192.168.100.253> (0, '\r\n{"group": "root", "uid": 0, "changed": false, "owner": "root", "state": "file", "gid": 0, "secontext": "system_u:object_r:admin_home_t:s0", "mode": "0644", "path": "/root/soft/jdk-8u202-linux-x64.rpm", "invocation": {"module_args": {"directory_mode": null, "force": false, "remote_src": null, "path": "/root/soft/jdk-8u202-linux-x64.rpm", "owner": "root", "follow": false, "group": "root", "unsafe_writes": null, "state": "file", "content": null, "serole": null, "diff_peek": null, "setype": null, "dest": "/root/soft/jdk-8u202-linux-x64.rpm", "selevel": null, "original_basename": "jdk-8u202-linux-x64.rpm", "regexp": null, "validate": null, "src": "jdk-8u202-linux-x64.rpm", "seuser": null, "recurse": false, "delimiter": null, "mode": "0644", "attributes": null, "backup": null}}, "diff": {"after": {"path": "/root/soft/jdk-8u202-linux-x64.rpm"}, "before": {"path": "/root/soft/jdk-8u202-linux-x64.rpm"}}, "size": 178418154}\r\n', 'Shared connection to 192.168.100.253 closed.\r\n')
papachiropa

2020/06/03 04:32

ok: [192.168.100.253] => { "changed": false, "checksum": "565f4ea1526cb88b4251a3e4982f3bcc16112a01", "diff": { "after": { "path": "/root/soft/jdk-8u202-linux-x64.rpm" }, "before": { "path": "/root/soft/jdk-8u202-linux-x64.rpm" } }, "gid": 0, "group": "root", "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "delimiter": null, "dest": "/root/soft/jdk-8u202-linux-x64.rpm", "diff_peek": null, "directory_mode": null, "follow": false, "force": false, "group": "root", "mode": "0644", "original_basename": "jdk-8u202-linux-x64.rpm", "owner": "root", "path": "/root/soft/jdk-8u202-linux-x64.rpm", "recurse": false, "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": "jdk-8u202-linux-x64.rpm", "state": "file", "unsafe_writes": null, "validate": null } }, "mode": "0644", "owner": "root", "path": "/root/soft/jdk-8u202-linux-x64.rpm", "secontext": "system_u:object_r:admin_home_t:s0", "size": 178418154, "state": "file", "uid": 0 }
papachiropa

2020/06/03 04:33

TASK [install JDK 14 from a local file] ***************************************************************************************************** task path: /tmp/OracleJDK.yml:14 Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/yum.py <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' <192.168.100.253> (0, '/root\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037 `" && echo ansible-tmp-1591157269.98-51058733773037="` echo /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037 `" ) && sleep 0'"'"'' <192.168.100.253> (0, 'ansible-tmp-1591157269.98-51058733773037=/root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037\n', '') <192.168.100.253> PUT /tmp/tmpLIpm3X TO /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/yum.py <192.168.100.253> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 '[192.168.100.253]' <192.168.100.253> (0, 'sftp> put /tmp/tmpLIpm3X /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/yum.py\n', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 192.168.100.253 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/ /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/yum.py && sleep 0'"'"'' <192.168.100.253> (0, '', '') <192.168.100.253> ESTABLISH SSH CONNECTION FOR USER: root <192.168.100.253> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/fc67d50775 -tt 192.168.100.253 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/yum.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1591157269.98-51058733773037/" > /dev/null 2>&1 && sleep 0'"'"'' <192.168.100.253> (0, '\r\n{"msg": "", "invocation": {"module_args": {"allow_downgrade": false, "name": ["/root/soft/jdk-8u202-linux-x64.rpm"], "list": null, "install_repoquery": true, "conf_file": null, "disable_gpg_check": false, "state": "present", "disablerepo": null, "update_cache": false, "enablerepo": null, "exclude": null, "security": false, "validate_certs": true, "installroot": "/", "skip_broken": false}}, "changed": false, "results": ["2000:jdk1.8-1.8.0_202-fcs.x86_64 providing /root/soft/jdk-8u202-linux-x64.rpm is already installed"], "rc": 0}\r\n', 'Shared connection to 192.168.100.253 closed.\r\n') ok: [192.168.100.253] => { "changed": false, "invocation": { "module_args": { "allow_downgrade": false, "conf_file": null, "disable_gpg_check": false, "disablerepo": null, "enablerepo": null, "exclude": null, "install_repoquery": true, "installroot": "/", "list": null, "name": [ "/root/soft/jdk-8u202-linux-x64.rpm" ], "security": false, "skip_broken": false, "state": "present", "update_cache": false, "validate_certs": true } }, "msg": "", "rc": 0, "results": [ "2000:jdk1.8-1.8.0_202-fcs.x86_64 providing /root/soft/jdk-8u202-linux-x64.rpm is already installed" ] } META: ran handlers META: ran handlers to retry, use: --limit @/tmp/OracleJDK.retry PLAY RECAP ********************************************************************************************************************************** 192.168.100.251 : ok=0 changed=0 unreachable=1 failed=0 192.168.100.253 : ok=3 changed=0 unreachable=0 failed=0
comefigo

2020/06/03 05:35

ありがとうございます。 デバックログにも出力されていますが、 「ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10」 を直接実行したらどうなりますでしょうか? あと、192.168.100.251 の公開鍵の所有権、実行権限なども教えて頂きたいです。
papachiropa

2020/06/03 05:53

[root@hoge user]# ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/root/.ssh/id_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname [command] 以上の様になりました。 192.168.100.251 の公開鍵の所有権、実行権限は以下になります。 [root@linux1 user]# ll ~/.ssh 合計 4 -rw-------. 1 root root 397 6月 1 15:36 authorized_keys
papachiropa

2020/06/03 05:55

ssh-keygen -pでパスワードを空にした上で、 ansible all -m ping -i hostsとansible-playbook OracleJDK.yml -i hostsを 実行すると成功したので、パスワード周りの設定がおかしいのかなという気がしてきました…
comefigo

2020/06/03 06:08

パスワード付きのSSH鍵でしたんですね・・・ であれば、あと一歩ですね。
papachiropa

2020/06/03 07:13

ssh-keygenで鍵のパスワードは解除し /etc/ansible/ansible.cfgで「ask_pass = True」に修正して playbook実行時にパスワードを求められるような形にしました。 最後までお付き合いいただき本当にありがとうございました。
comefigo

2020/06/03 08:42

いえいえ。解決されてよかったです。 ある程度理解されてから、パスワードの自動入力も検討したほうがいいかもしれないですね。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問