From: Anil Belur Date: Sat, 20 Dec 2025 23:16:23 +0000 (+1000) Subject: fix: Add version check for pyenv_cmd usage X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;ds=inline;p=ansible%2Froles%2Fpython-install.git fix: Add version check for pyenv_cmd usage 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 Signed-off-by: Anil Belur --- diff --git a/tasks/main.yml b/tasks/main.yml index 3634eee..9b41f94 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -71,14 +71,18 @@ - 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 }}' - 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: