0
0

Ansible 2.17.2→2.16.3にダウングレードする方法

Last updated at Posted at 2024-08-01

1. 結論

$ pipx uninstall ansible
$ pipx uninstall ansible-core
$ pipx install "ansible-core=2.16.3"
$ pipx install ansible

2. 前提条件

  • pipxを導入済みであること

(参考:pipx install pipx

3. 背景

ansible.builtin.dnf を実行すると以下エラーが発生した。

The full traceback is:
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1131, in _get_spec
  File "<frozen importlib._bootstrap_external>", line 1112, in _legacy_get_spec
  File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 544, in spec_from_file_location
  File "/tmp/ansible_ansible.legacy.dnf_payload_akxd0m9j/ansible_ansible.legacy.dnf_payload.zip/ansible/module_utils/basic.py", line 5
SyntaxError: future feature annotations is not defined

playbookの内容とインベントリは以下。

main.yml
---
- name: Dnf test
  hosts: all

  tasks:
    - name: Install
      ansible.builtin.dnf:
        name: make, gcc, perl-IPC-Cmd
        state: present
inventory.yml
---
all:
  children:
    rhel:
      vars:
        ansible_ssh_user: root
        ansible_python_interpreter: /usr/bin/python3.11
      hosts:
        almalinux8:
          ansible_host: 100.115.92.204

上記を$ ansible-playbook -i inventory.yml main.ymlするとSyntaxError: future feature annotations is not definedが発生する。Ansible 2.17系からPython 3.6以下が切り捨てられることによる影響っぽい気がするが、ansible_python_interpreterでPython 3.11を指定しているので問題ないはずである。にも関わらずエラーが消えなかったためダウングレードを実施したことが背景である。なお、ダウングレード後は上記コマンドで動作した。

4. 感想

ansible_python_interpreterでPythonを指定しないと以下WARNINGがでる。

[WARNING]: Platform linux on host almalinux8 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.17/reference_appendices/interpreter_discovery.html for more information.

Ansible実行環境はPython 3.12で対象ホストのPythonは3.9なのでWARNINGが出ている。ということで、対象ホストのデフォルトはそもそも3.9であり、SyntaxError: future feature annotations is not definedは発生しないように思う。なお対象ホストはAlma Linux8.10である。

# cat /etc/redhat-release 
AlmaLinux release 8.10 (Cerulean Leopard)

一体どこのPythonを参照しに行っているのだろうか…。いずれにせよ、ansible_python_interpreterで指定したPythonを使ってくれないのは事実であるため、2.17.2の使用は控えることにした。

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