CentOS8のサーバーにAnsible playbookが実行できなかったお話(解決)
CentOS8が導入されたサーバーに対して簡易的な内容のAnsibleを叩いたら、
2件のエラーパターンが出てくるようになってしまった。
☑Ansible 2.3.2.0で起きたエラー
FAILED! => {"changed": false, "cmd": "dnf install -y python2-dnf", "msg": "Error: Unable to find a match", "rc": 1, "stderr": "Error: Unable to find a match\n",
☑Ansible 2.7.8で起きたエラー
FAILED! => {"changed": false, "cmd": "dnf install -y python2-dnf", "msg": "Error: Unable to find a match", "rc": 1, "stderr": "Error: Unable to find a match\n",
ymlの内容はyum モジュールでパッケージのインストールしか書いてないシンプルなyml。
Twitterなどで情報を頂き解決したので、その備忘録をまとめておく。
1.解決策について
解決策①: Ansible 2.8.5以降にする(一番間違いない)
ansible_python_interpreterを指定しないですみます。
解決策② どうしてもAnsible 2.8.5以降にできない場合(この記事でお話している所 Ansibleバージョンは2.7.8)
FAILED! => {"changed": false, "cmd": "dnf install -y python2-dnf", "msg": "Error: Unable to find a match", "rc": 1, "stderr": "Error: Unable to find a match\n",が起きた環境
1."実行元"Ansibleのバージョンを2.4以上にして、/usr/libexec/platform-pythonをansible_python_interpreterで指定する ←せいかい
# ansible-playbook --ask-pass -i inventory setup.yml -e 'ansible_python_interpreter=/usr/libexec/platform-python'
解決策不明:だいぶ前のAnsibleバージョン(元々問題が起きた環境の2.3.2.0)
fatal: [hogehoge]: FAILED! => {"changed": false, "failed": true, "msg": "python2 yum module is needed for this module"}が起きた環境
解決策があるかは現段階では不明…バージョン2.4以上にあげるしかないと思っている。
3. Twitterのリプライでアドバイスを頂いて間違いに気づけました🙇
元々この記事で解決策②にpython3を入れて、ansible_python_interpreterでpython3のパスを指定する方法を書いていましたが不要な事をしていたので修正しました。
ansible_python_interpreterでpython3を指定する⇒/usr/libexec/platform-pythonを指定する
リプライで@sugitkさんにスマートな方法のアドバイスを沢山頂けたおかげです、感謝致します🙇
ご確認いただきありがとうございます ^^
— すぎむら46 (@sugitk) October 17, 2019
CentOS8 (RHEL8) では、OS 制御用に /usr/libexec/platform-python というのが標準でインストールされています。パターン②(ansible2.7.8)の場合でも、それを指定すれば別にPython3をインストールしなくても動作すると思います。
CentOS8に対してAnsible playbookを実行できなかったメモ
— Yuya Matoba (@lezosan) October 17, 2019
結論、Ansibleバージョンが2.4以上にして、実行先のCentOSにpython3を導入ansible_python_interpreterでpython3指定して解決。
CentOS8のサーバーにAnsible playbookが実行できなかったお話 - 窓とかペンギンとか https://t.co/y9oXQqSxnY