Sunday, September 29, 2024

Nâng cấp phiên bản cho Ansible

-

Ansible version là rất quan trọng vì nó xác định phiên bản cụ thể của Ansible mà bạn đang sử dụng. Phiên bản Ansible có thể ảnh hưởng đến tính năng, khả năng tương thích, sự ổn định và các cú pháp trong playbook của bạn. Dưới đây là một số lý do tại sao phiên bản Ansible quan trọng:

  • Tính năng và cú pháp: Mỗi phiên bản Ansible có thể có các tính năng mới, cú pháp cải tiến và cập nhật giao diện lệnh. Việc sử dụng phiên bản phù hợp sẽ cho phép bạn tận dụng những cải tiến này và sử dụng cú pháp mới nhất.
  • Tương thích hệ thống: Mỗi phiên bản Ansible có thể có yêu cầu về phiên bản Python, các thư viện phụ thuộc và các yêu cầu hệ thống khác. Đảm bảo bạn sử dụng phiên bản Ansible tương thích với hệ thống của bạn sẽ giúp tránh các xung đột và lỗi không mong muốn.
  • Sửa lỗi và bảo mật: Các phiên bản mới của Ansible thường đi kèm với các bản vá lỗi và cải thiện bảo mật. Bằng cách sử dụng phiên bản mới nhất, bạn sẽ có lợi ích từ các bản vá lỗi và bảo mật được cung cấp bởi cộng đồng và nhà phát triển Ansible.
  • Hỗ trợ và tài liệu: Cộng đồng và nhà phát triển Ansible thường cung cấp hỗ trợ và tài liệu cho các phiên bản mới nhất. Việc sử dụng phiên bản mới nhất sẽ giúp bạn tận dụng tài nguyên này và nhận được sự hỗ trợ tốt nhất khi cần thiết.

Vì vậy, quan trọng để kiểm soát và quản lý phiên bản Ansible một cách cẩn thận, đảm bảo sử dụng phiên bản phù hợp với yêu cầu và môi trường của bạn.

Ví dụ cho phiên bản Ansbile không tương thích với module nên bạn không thể cài module cisco.nxos với phiên bản Ansible 2.5.1 hiện tại.

$ ansible-galaxy collection install cisco.nxos
- downloading role 'collection', owned by 
 [WARNING]: - collection was NOT installed successfully: Content has no field named 'owner'

ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

Trên trang chủ cũng yêu cầu phải là Ansible 2.9.10 hoặc lớn hơn mới cài được module này.

Để nâng cấp phiên bản Ansible từ 2.5.1 lên 2.9.10, bạn có thể sử dụng các công cụ quản lý gói như pip để cài đặt phiên bản mới nhất của Ansible. Dưới đây là các bước thực hiện nâng cấp:

Đảm bảo rằng bạn đã cài đặt pip, trình quản lý gói Python. Nếu chưa có, cài đặt nó bằng các lệnh sau:

sudo apt update
sudo apt install python3-pip

Kiểm tra phiên bản Ansible hiện tại bằng lệnh ansible –version:

$ ansible --version
ansible 2.5.1
  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/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Mar  8 2023, 18:40:28) [GCC 7.5.0]

Lưu lại phiên bản hiện tại của Ansible để tham khảo sau này. Cài đặt Ansible với phiên bản cụ thể bằng lệnh pip3 install --upgrade ansible==2.9.10. Thay 2.9.10 bằng phiên bản Ansible mới nhất mà bạn muốn cài đặt.

pip3 install --upgrade ansible==2.9.10

Hoặc bạn có thể cài đặt phiên bản mới nhất của Ansible bằng lệnh:

pip3 install --upgrade ansible

Lệnh trên sẽ cài đặt phiên bản Ansible mới nhất có sẵn trên PyPI (Python Package Index). Trong quá quá trình cài đặt gói setuptools_rust nếu không thành công là do thiếu các phụ thuộc hoặc vấn đề xảy ra trong quá trình cài đặt.

$ pip3 install --upgrade ansible==2.9.10
Collecting ansible==2.9.10
  Downloading https://files.pythonhosted.org/packages/03/4f/cccab1ec2e0ecb05120184088e00404b38854809cf35aa76889406fbcbad/ansible-2.9.10.tar.gz (14.2MB)
    100% |████████████████████████████████| 14.2MB 71kB/s 
Collecting PyYAML (from ansible==2.9.10)
  Downloading https://files.pythonhosted.org/packages/b3/85/79b9e5b4e8d3c0ac657f4e8617713cca8408f6cdc65d2ee6554217cedff1/PyYAML-6.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (603kB)
    100% |████████████████████████████████| 604kB 1.0MB/s 
Collecting cryptography (from ansible==2.9.10)
  Downloading https://files.pythonhosted.org/packages/f7/80/04cc7637238b78f8e7354900817135c5a23cf66dfb3f3a216c6d630d6833/cryptography-40.0.2.tar.gz (625kB)
    100% |████████████████████████████████| 634kB 1.3MB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-_1cdygqr/cryptography/setup.py", line 18, in <module>
        from setuptools_rust import RustExtension
    ModuleNotFoundError: No module named 'setuptools_rust'
    
            =============================DEBUG ASSISTANCE==========================
            If you are seeing an error here please try the following to
            successfully install cryptography:
    
            Upgrade to the latest pip and try again. This will fix errors for most
            users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
            =============================DEBUG ASSISTANCE==========================
    
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-_1cdygqr/cryptography/

Để giải quyết vấn đề này, bạn hãy cài đặt gói setuptools_rusttrước khi cài đặt Ansible bằng lệnh pip install setuptools_rust.

$ pip3 install setuptools_rust
Collecting setuptools_rust
  Downloading https://files.pythonhosted.org/packages/66/ca/66bdf8f326977098eff28c314c8f825bc28d6986944c590e40ad0f74c5f0/setuptools_rust-1.1.2-py3-none-any.whl
Collecting typing-extensions>=3.7.4.3 (from setuptools_rust)
  Downloading https://files.pythonhosted.org/packages/45/6b/44f7f8f1e110027cf88956b59f2fad776cca7e1704396d043f89effd3a0e/typing_extensions-4.1.1-py3-none-any.whl
Collecting setuptools>=46.1 (from setuptools_rust)
  Downloading https://files.pythonhosted.org/packages/b0/3a/88b210db68e56854d0bcf4b38e165e03be377e13907746f825790f3df5bf/setuptools-59.6.0-py3-none-any.whl (952kB)
    100% |████████████████████████████████| 962kB 946kB/s 
Collecting semantic-version<3,>=2.8.2 (from setuptools_rust)
  Downloading https://files.pythonhosted.org/packages/6a/23/8146aad7d88f4fcb3a6218f41a60f6c2d4e3a72de72da1825dc7c8f7877c/semantic_version-2.10.0-py2.py3-none-any.whl
Installing collected packages: typing-extensions, setuptools, semantic-version, setuptools-rust
  Found existing installation: setuptools 39.0.1
    Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed semantic-version-2.10.0 setuptools-59.6.0 setuptools-rust-1.1.2 typing-extensions-4.1.1

Tiếp theo bạn hãy nâng cấp pip3.

$ pip3 install --upgrade pip

Sau đó tiến hành cài lại Ansible.

$ pip3 install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
    100% |████████████████████████████████| 1.7MB 601kB/s 
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-21.3.1
root@k8s-loadbalancer2:/home/ansible-network# pip3 install --upgrade ansible==2.9.1
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Collecting ansible==2.9.1
  Downloading ansible-2.9.1.tar.gz (14.1 MB)
     |████████████████████████████████| 14.1 MB 13.6 MB/s            
  Preparing metadata (setup.py) ... done
Requirement already satisfied: jinja2 in /usr/local/lib/python3.6/dist-packages (from ansible==2.9.1) (3.0.3)
Requirement already satisfied: PyYAML in /usr/local/lib/python3.6/dist-packages (from ansible==2.9.1) (6.0)
Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible==2.9.1) (2.1.4)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.6/dist-packages (from jinja2->ansible==2.9.1) (2.0.1)
Building wheels for collected packages: ansible
  Building wheel for ansible (setup.py) ... done
  Created wheel for ansible: filename=ansible-2.9.1-py3-none-any.whl size=16130493 sha256=ec4a5e3eded41093f97a71dbe173dfd885a775916c0007ce06311e851e0feab0
  Stored in directory: /root/.cache/pip/wheels/03/f3/a0/ceb01fa023d3a4af71e3556c01841e413ad39451b2011de4dd
Successfully built ansible
Installing collected packages: ansible
Successfully installed ansible-2.9.1

Kiểm tra lại phiên bản Ansible sau khi nâng cấp bằng lệnh dưới để đảm bảo rằng phiên bản đã được cập nhật thành công.

$ ansible --version
ansible 2.9.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.9 (default, Mar 10 2023, 16:46:00) [GCC 8.4.0]

Vui lòng lưu ý rằng việc nâng cấp Ansible có thể tương thích với phiên bản Python và các yêu cầu hệ thống khác. Nếu gặp sự cố hoặc vấn đề không mong muốn, hãy tham khảo tài liệu và hỗ trợ từ trang chủ Ansible hoặc cộng đồng Ansible để biết thêm thông tin và giúp đỡ cụ thể với quá trình nâng cấp.

Sau khi nâng cấp xong Ansible bạn có thể cài module cisco.nxos bình thường.

$ ansible-galaxy collection install cisco.nxos
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/cisco-nxos-4.3.0.tar.gz to /root/.ansible/tmp/ansible-local-38786859tiswch2/tmpz9hi7txr/cisco-nxos-4.3.0-p1hm6v1d
Installing 'cisco.nxos:4.3.0' to '/root/.ansible/collections/ansible_collections/cisco/nxos'
Downloading https://galaxy.ansible.com/download/ansible-netcommon-5.1.1.tar.gz to /root/.ansible/tmp/ansible-local-38786859tiswch2/tmpz9hi7txr/ansible-netcommon-5.1.1-8ybox0mm
cisco.nxos:4.3.0 was installed successfully
Installing 'ansible.netcommon:5.1.1' to '/root/.ansible/collections/ansible_collections/ansible/netcommon'
Downloading https://galaxy.ansible.com/download/ansible-utils-2.10.2.tar.gz to /root/.ansible/tmp/ansible-local-38786859tiswch2/tmpz9hi7txr/ansible-utils-2.10.2-cs0p1098
ansible.netcommon:5.1.1 was installed successfully
Installing 'ansible.utils:2.10.2' to '/root/.ansible/collections/ansible_collections/ansible/utils'
ansible.utils:2.10.2 was installed successfully

LEAVE A REPLY

Please enter your comment!
Please enter your name here

4,956FansLike
256FollowersFollow
223SubscribersSubscribe
spot_img

Related Stories