0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansibleコマンド実行すると "module_stdout": "/bin/sh: /usr/bin/python3: No such file or directory\r\n",が表示される事象

Last updated at Posted at 2023-12-03

概要

Windows端末にWSLからVirtualboxのゲストOS(CentOS7)にansibleコマンドで疎通確認しようとしましたが、python3のエラーによりコマンドが失敗しました。

事象

WSLにてリモートホストに対してAnsibleコマンドを実行して疎通したところ、以下のエラーが出ました。
※例) 192.168.0.25はリモートホストのIPアドレスです。

oot@DESKTOP-0S2U0NI:/usr/bin# ansible 192.168.0.25 -m ping -k
SSH password:
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/osx_say.py) as it seems to be invalid: No module named 'distutils.spawn'
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/say.py) as it seems to be invalid: No module named 'distutils.spawn'
192.168.0.25 | FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 192.168.0.25 closed.\r\n",
    "module_stdout": "/bin/sh: /usr/bin/python3: No such file or directory\r\n",
    "msg": "The module failed to execute correctly, you probably need to set the interpreter.\nSee stdout/stderr for the exact error",
    "rc": 127
}

原因

リモートホストにpython3でAnsibleを実行しようとしましたが、リモートホストにpython3がインストールされていないのが原因のエラーでした。

リモートホストにてpython3をインストールする方法

原因はリモートホストにSSH接続するとpython3がインストールされていませんでした。

以下のpython3のバージョンを確認するコマンドを実行しましたが、何も表示されませんでした。

python3 --verion

python3をインストールしました。

yum install python3
[root@localhost ~]# yum install python3
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
base                                                                                             | 3.6 kB  00:00:00
extras                                                                                           | 2.9 kB  00:00:00
updates                                                                                          | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package python3.x86_64 0:3.6.8-21.el7_9 will be installed
--> Processing Dependency: python3-libs(x86-64) = 3.6.8-21.el7_9 for package: python3-3.6.8-21.el7_9.x86_64
--> Processing Dependency: python3-setuptools for package: python3-3.6.8-21.el7_9.x86_64
--> Processing Dependency: python3-pip for package: python3-3.6.8-21.el7_9.x86_64
--> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python3-3.6.8-21.el7_9.x86_64
--> Running transaction check
---> Package python3-libs.x86_64 0:3.6.8-21.el7_9 will be installed
--> Processing Dependency: libtirpc.so.1()(64bit) for package: python3-libs-3.6.8-21.el7_9.x86_64
---> Package python3-pip.noarch 0:9.0.3-8.el7 will be installed
---> Package python3-setuptools.noarch 0:39.2.0-10.el7 will be installed
--> Running transaction check
---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                            Arch                   Version                        Repository               Size
========================================================================================================================
Installing:
 python3                            x86_64                 3.6.8-21.el7_9                 updates                  71 k
Installing for dependencies:
 libtirpc                           x86_64                 0.2.4-0.16.el7                 base                     89 k
 python3-libs                       x86_64                 3.6.8-21.el7_9                 updates                 7.0 M
 python3-pip                        noarch                 9.0.3-8.el7                    base                    1.6 M
 python3-setuptools                 noarch                 39.2.0-10.el7                  base                    629 k

Transaction Summary
========================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 9.3 M
Installed size: 48 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): python3-3.6.8-21.el7_9.x86_64.rpm                                                         |  71 kB  00:00:00
(2/5): libtirpc-0.2.4-0.16.el7.x86_64.rpm                                                        |  89 kB  00:00:00
(3/5): python3-pip-9.0.3-8.el7.noarch.rpm                                                        | 1.6 MB  00:00:00
(4/5): python3-setuptools-39.2.0-10.el7.noarch.rpm                                               | 629 kB  00:00:01
(5/5): python3-libs-3.6.8-21.el7_9.x86_64.rpm                                                    | 7.0 MB  00:00:02
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   4.0 MB/s | 9.3 MB  00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libtirpc-0.2.4-0.16.el7.x86_64                                                                       1/5
  Installing : python3-setuptools-39.2.0-10.el7.noarch                                                              2/5
  Installing : python3-pip-9.0.3-8.el7.noarch                                                                       3/5
  Installing : python3-3.6.8-21.el7_9.x86_64                                                                        4/5
  Installing : python3-libs-3.6.8-21.el7_9.x86_64                                                                   5/5
  Verifying  : libtirpc-0.2.4-0.16.el7.x86_64                                                                       1/5
  Verifying  : python3-libs-3.6.8-21.el7_9.x86_64                                                                   2/5
  Verifying  : python3-3.6.8-21.el7_9.x86_64                                                                        3/5
  Verifying  : python3-setuptools-39.2.0-10.el7.noarch                                                              4/5
  Verifying  : python3-pip-9.0.3-8.el7.noarch                                                                       5/5

Installed:
  python3.x86_64 0:3.6.8-21.el7_9

Dependency Installed:
  libtirpc.x86_64 0:0.2.4-0.16.el7            python3-libs.x86_64 0:3.6.8-21.el7_9   python3-pip.noarch 0:9.0.3-8.el7
  python3-setuptools.noarch 0:39.2.0-10.el7

Complete!
[root@localhost ~]#

python3のインストールを確認しました。

[root@localhost ~]# python3 --version
Python 3.6.8
[root@localhost ~]#

再度ローカル端末からWSLを開き、リモートホストに対してansibleでpingを実行したら成功しました。

root@DESKTOP-0S2U0NI:/usr/bin# ansible 192.168.0.25 -m ping -k
SSH password:
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/osx_say.py) as it seems to be invalid: No module named 'distutils.spawn'
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/say.py) as it seems to be invalid: No module named 'distutils.spawn'
192.168.0.25 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

リモートホストにてpython2系でAnsible実行する方法

リモートホストにpython3のパッケージをインストール出来ない場合は、
python2でAnsible動作させる必要があります。

Windows端末のWSLにてpython2系のインストールをする

apt install python

例 python2.7を今回リンク先名「/usr/bin/python2」にリンクさせました。

in -snf 元のデータ リンク先名
ln -snf /usr/bin/python2.7 /usr/bin/python2

以下のインベントリファイルを開き、Ansible2で動作させる設定を入れました。
以下のサイトを参考にしました。
https://iret.media/32424

vi /etc/ansible/hosts

[group1]
192.168.0.25 ansible_python_interpreter=/usr/bin/python2

成功しました。

root@DESKTOP-0S2U0NI:/etc/ansible# ansible 192.168.0.25 -m ping -k
SSH password:
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/osx_say.py) as it seems to be
invalid: No module named 'distutils.spawn'
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/say.py) as it seems to be invalid:
No module named 'distutils.spawn'
192.168.0.25 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/osx_say.py) as it seems to be
invalid: No module named 'distutils.spawn'
[WARNING]: Skipping plugin (/usr/lib/python3/dist-packages/ansible/plugins/callback/say.py) as it seems to be invalid:

上記ワーニングは出ますが現在調査しています。ワーニングのため、動作には影響ないです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?