fix: Add version check for pyenv_cmd usage 19/74019/2 master
authorAnil Belur <abelur@linuxfoundation.org>
Sat, 20 Dec 2025 23:16:23 +0000 (09:16 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Sun, 21 Dec 2025 22:22:45 +0000 (08:22 +1000)
The pyenv_cmd variable is only set for Ubuntu >= 22.04 and CentOS >= 9,
but was being used unconditionally in 'pyenv global' commands. This
caused failures on Ubuntu 20.04 and older CentOS versions.

Fixed by adding proper version checks using ansible_facts to:
- Only run 'pyenv global' on Ubuntu >= 22.04
- Only run 'pyenv global' on CentOS >= 9
- Avoid deprecation warnings by using ansible_facts instead of
  ansible_distribution variables

This resolves the error:
  'pyenv_cmd' is undefined

Change-Id: I768f327edc02c04365f8be60f94d32fe21eed47d
Signed-off-by: Anil Belur <askb23@gmail.com>
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
tasks/main.yml

index 3634eee..9b41f94 100644 (file)
         - molecule-idempotence-notest
     - name: 'Set the required python 3.x versions using pyenv on Ubuntu'
       ansible.builtin.command: 'pyenv global system {{ pyenv_cmd }}'
         - molecule-idempotence-notest
     - name: 'Set the required python 3.x versions using pyenv on Ubuntu'
       ansible.builtin.command: 'pyenv global system {{ pyenv_cmd }}'
-      when: ansible_distribution == 'Ubuntu'
+      when:
+        - ansible_facts['distribution'] == 'Ubuntu'
+        - ansible_facts['distribution_version'] is version('22.04', '>=')
       register: pyenv_global_ubuntu_result
       changed_when: false
       tags:
         - molecule-idempotence-notest
     - name: 'Set the required python 3.x versions using pyenv on CentOS'
       ansible.builtin.command: 'pyenv global {{ pyenv_cmd }}'
       register: pyenv_global_ubuntu_result
       changed_when: false
       tags:
         - molecule-idempotence-notest
     - name: 'Set the required python 3.x versions using pyenv on CentOS'
       ansible.builtin.command: 'pyenv global {{ pyenv_cmd }}'
-      when: ansible_distribution == 'CentOS'
+      when:
+        - ansible_facts['distribution'] == 'CentOS'
+        - ansible_facts['distribution_major_version'] | int >= 9
       register: pyenv_global_centos_result
       changed_when: false
       tags:
       register: pyenv_global_centos_result
       changed_when: false
       tags: