Ansible kiểm tra phiên bản python

Tôi đang sử dụng Ansible 2. 9. 2 với một sửa đổi được áp dụng cho bản đồ INTERPRETER_PYTHON_DISTRO_MAP [để hỗ trợ Debian 10] trong lib/ansible/config/base. yml từ Mặc định thành python3 trên Debian 10 #63097 yêu cầu hợp nhất. Thay đổi này sẽ có hiệu lực trong Ansible 2. 10

INTERPRETER_PYTHON:
  name: Python interpreter path [or automatic discovery behavior] used for module execution
  default: auto_legacy
  env: [{name: ANSIBLE_PYTHON_INTERPRETER}]
  ini:
  - {key: interpreter_python, section: defaults}
  vars:
  - {name: ansible_python_interpreter}
  version_added: "2.8"
  description:
  - Path to the Python interpreter to be used for module execution on remote targets, or an automatic discovery mode.
    Supported discovery modes are ``auto``, ``auto_silent``, and ``auto_legacy`` [the default]. All discovery modes
    employ a lookup table to use the included system Python [on distributions known to include one], falling back to a
    fixed ordered list of well-known Python interpreter locations if a platform-specific default is not available. The
    fallback behavior will issue a warning that the interpreter should be set explicitly [since interpreters installed
    later may change which one is used]. This warning behavior can be disabled by setting ``auto_silent``. The default
    value of ``auto_legacy`` provides all the same behavior, but for backwards-compatibility with older Ansible releases
    that always defaulted to ``/usr/bin/python``, will use that interpreter if present [and issue a warning that the
    default behavior will change to that of ``auto`` in a future Ansible release.
INTERPRETER_PYTHON_DISTRO_MAP:
  name: Mapping of known included platform pythons for various Linux distros
  default:
    centos: &rhelish
      '6': /usr/bin/python
      '8': /usr/libexec/platform-python
    debian:
      '10': /usr/bin/python3
    fedora:
      '23': /usr/bin/python3
    redhat: *rhelish
    rhel: *rhelish
    ubuntu:
      '14': /usr/bin/python
      '16': /usr/bin/python3
  version_added: "2.8"
  # FUTURE: add inventory override once we're sure it can't be abused by a rogue target
  # FUTURE: add a platform layer to the map so we could use for, eg, freebsd/macos/etc?
INTERPRETER_PYTHON_FALLBACK:
  name: Ordered list of Python interpreters to check for in discovery
  default:
  - /usr/bin/python
  - python3.7
  - python3.6
  - python3.5
  - python2.7
  - python2.6
  - /usr/libexec/platform-python
  - /usr/bin/python3
  - python
  # FUTURE: add inventory override once we're sure it can't be abused by a rogue target
  version_added: "2.8"

Kể từ Ansible 2. 8, giá trị mặc định của

$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10 22:02 /usr/bin/python2.7
lrwxrwxrwx 1 root root      33 Oct 10 22:02 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Mar  4  2019 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7m
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root      14 Mar  4  2019 /usr/bin/python-config -> python2-config
0 là
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10 22:02 /usr/bin/python2.7
lrwxrwxrwx 1 root root      33 Oct 10 22:02 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Mar  4  2019 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7m
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root      14 Mar  4  2019 /usr/bin/python-config -> python2-config
1, có nghĩa là nó sẽ thích
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10 22:02 /usr/bin/python2.7
lrwxrwxrwx 1 root root      33 Oct 10 22:02 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Mar  4  2019 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7m
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root      14 Mar  4  2019 /usr/bin/python-config -> python2-config
2 [nếu nó tồn tại] hơn phiên bản Python được phát hiện. Bạn có thể đặt nó thành
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       7 Mar  4  2019 /usr/bin/python -> python2
lrwxrwxrwx 1 root root       9 Mar  4  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3689352 Oct 10 22:02 /usr/bin/python2.7
lrwxrwxrwx 1 root root      33 Oct 10 22:02 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Mar  4  2019 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 26  2019 /usr/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7
-rwxr-xr-x 2 root root 4877888 Apr  3  2019 /usr/bin/python3.7m
lrwxrwxrwx 1 root root      10 Mar 26  2019 /usr/bin/python3m -> python3.7m
lrwxrwxrwx 1 root root      14 Mar  4  2019 /usr/bin/python-config -> python2-config
3, sau này nó sẽ được mặc định, vì vậy nó sẽ hoạt động ngược lại

Phiên bản Python nào ansible đang sử dụng?

Hiện tại Ansible có thể chạy từ bất kỳ máy nào có Python 2 [phiên bản 2. 7] hoặc Python 3 [phiên bản 3. 5 trở lên] đã cài đặt. Windows không được hỗ trợ cho máy điều khiển. Điều này bao gồm Red Hat, Debian, CentOS, macOS, bất kỳ BSD nào, v.v.

Làm cách nào để tìm phiên bản Python của bạn?

Để lấy Phiên bản của Trình thông dịch python, chúng được liệt kê như sau. .
sử dụng sys. phương pháp phiên bản
Sử dụng hàm python_version[]
Sử dụng lệnh Python -V

Làm cách nào để thay đổi phiên bản Python ansible?

Trong trường hợp này, bạn cần sudo su sau đó cài đặt ansible với pip3 , nếu không, nó sẽ chỉ cài đặt cho tài khoản của bạn . ~/. cục bộ/thùng. Theo phiên bản pip mới, bạn nên sử dụng python3 -m pip install xxx hơn là thực thi trực tiếp pip3 install xxx.

Làm cách nào để cài đặt ansible với Python 3?

Chạy nhánh phát triển từ một bản sao .
Thiết lập môi trường Ansible. Sử dụng Bash. nguồn $. /hack/env-thiết lập. .
Cài đặt các phụ thuộc Python. $ python3 -m cài đặt pip --user -r. /yêu cầu. txt
Cập nhật nhánh phát triển của lõi ansible trên máy cục bộ của bạn. Sử dụng pull-with-rebase để mọi thay đổi cục bộ được phát lại

Chủ Đề