Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: '>' not supported between instances of 'str' and 'int' during build process in Ansible Builder 3.x.x #723

Closed
eanar opened this issue Feb 8, 2025 · 3 comments

Comments

@eanar
Copy link

eanar commented Feb 8, 2025

Description:
I encountered a TypeError during the build process with Ansible Builder when running the ansible-builder build command. The error occurs because a comparison (>) is being made between a string and an integer, which is not supported. This error is likely caused by improper handling of version values or other numerical comparisons in the code.


Steps to Reproduce:

  1. Set up a virtual environment or use a clean Python environment.
  2. Install ansible-builder version 3.0.1 (or another version in the 3.x.x series):
    pip install ansible-builder==3.0.1
  3. Create a simple requirements.yml with basic role/collection definitions (optional, the error might happen even without specific collections defined).
  4. Run the build command:
    ansible-builder build -t test

Expected Behavior:
The ansible-builder build process should complete successfully without errors.


Actual Behavior:
The build process fails with the following error:

TypeError: '>' not supported between instances of 'str' and 'int'

Version Information:

  • ansible-builder version: 3.0.1 (error occurs with other 3.x.x versions as well)
  • Python version: 3.12
  • Operating System: Ubuntu 22.04 (or your OS version)
  • ansible-runner version: [If known]
  • Other relevant package versions: [List any other dependencies related to Ansible Builder]

Code Snippets of Interest:

The error appears to stem from comparisons in the code where version values are compared directly with integers. For instance:

  1. In containerfile.py:

    if self.definition.version >= 3:

    The self.definition.version variable is likely being treated as a string, which causes the error.

  2. In user_definition.py:

    if self.version > 2:

    Similar issue with self.version being treated as a string during the comparison.


Additional Information:

  • The error consistently occurs during the build process, even with minimal setup (e.g., an empty requirements.yml).
  • The issue may be related to version handling or type comparisons in Ansible Builder's internal code.

Possible Solutions:

  • It appears that the version values should be cast to integers before making comparisons. For example, changing:

    if self.definition.version >= 3:

    to:

    if int(self.definition.version) >= 3:
  • This change may also be necessary in other locations where version or numerical values are compared.


Screenshots / Logs:

  (ansible-builder-env) eanar@MACHINE:~/eanar/src$ ansible-builder build -t test
TypeError: '>' not supported between instances of 'str' and 'int'
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ pip uninstall ansible-builder
Found existing installation: ansible-builder 3.1.0
Uninstalling ansible-builder-3.1.0:
  Would remove:
    /home/eanar/ansible-builder-env/bin/ansible-builder
    /home/eanar/ansible-builder-env/lib/python3.12/site-packages/ansible_builder-3.1.0.dist-info/*
    /home/eanar/ansible-builder-env/lib/python3.12/site-packages/ansible_builder/*
Proceed (Y/n)? y
  Successfully uninstalled ansible-builder-3.1.0
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ pip install ansible-builder==4.0.0
ERROR: Ignored the following yanked versions: 0.4.1, 0.4.2
ERROR: Could not find a version that satisfies the requirement ansible-builder==4.0.0 (from versions: 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.1, 0.4.0, 0.5.0, 0.5.1, 0.6.0, 1.0.0.0a1, 1.0.0.0a2, 1.0.0.0b1, 1.0.0.0rc1, 1.0.0, 1.0.1, 1.1.0, 1.2.0, 3.0.0.0b1, 3.0.0rc1, 3.0.0rc2, 3.0.0, 3.0.1, 3.1.0)
ERROR: No matching distribution found for ansible-builder==4.0.0
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ pip install ansible-builder==3.0.1
Collecting ansible-builder==3.0.1
  Downloading ansible_builder-3.0.1-py3-none-any.whl.metadata (2.7 kB)
Requirement already satisfied: PyYAML in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from ansible-builder==3.0.1) (6.0.2)
Collecting requirements-parser (from ansible-builder==3.0.1)
  Downloading requirements_parser-0.11.0-py3-none-any.whl.metadata (4.7 kB)
Requirement already satisfied: bindep in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from ansible-builder==3.0.1) (2.12.0)
Requirement already satisfied: jsonschema in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from ansible-builder==3.0.1) (4.23.0)
Requirement already satisfied: Parsley in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from bindep->ansible-builder==3.0.1) (1.3)
Requirement already satisfied: pbr>=2.0.0 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from bindep->ansible-builder==3.0.1) (6.1.1)
Requirement already satisfied: distro>=1.7.0 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from bindep->ansible-builder==3.0.1) (1.9.0)
Requirement already satisfied: packaging in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from bindep->ansible-builder==3.0.1) (24.2)
Requirement already satisfied: attrs>=22.2.0 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from jsonschema->ansible-builder==3.0.1) (25.1.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from jsonschema->ansible-builder==3.0.1) (2024.10.1)
Requirement already satisfied: referencing>=0.28.4 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from jsonschema->ansible-builder==3.0.1) (0.36.2)
Requirement already satisfied: rpds-py>=0.7.1 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from jsonschema->ansible-builder==3.0.1) (0.22.3)
Collecting types-setuptools>=69.1.0 (from requirements-parser->ansible-builder==3.0.1)
  Downloading types_setuptools-75.8.0.20250110-py3-none-any.whl.metadata (2.2 kB)
Requirement already satisfied: setuptools in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from pbr>=2.0.0->bindep->ansible-builder==3.0.1) (75.8.0)
Requirement already satisfied: typing-extensions>=4.4.0 in /home/eanar/ansible-builder-env/lib/python3.12/site-packages (from referencing>=0.28.4->jsonschema->ansible-builder==3.0.1) (4.12.2)
Downloading ansible_builder-3.0.1-py3-none-any.whl (41 kB)
Downloading requirements_parser-0.11.0-py3-none-any.whl (14 kB)
Downloading types_setuptools-75.8.0.20250110-py3-none-any.whl (71 kB)
Installing collected packages: types-setuptools, requirements-parser, ansible-builder
Successfully installed ansible-builder-3.0.1 requirements-parser-0.11.0 types-setuptools-75.8.0.20250110
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ ansible-builder build -t test
TypeError: '>' not supported between instances of 'str' and 'int'
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ ansible-builder --version
3.0.1
(ansible-builder-env) eanar@MACHINE:~/eanar/src$
(ansible-builder-env) eanar@MACHINE:~/eanar/src$
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ cat ~/.
./                         .bash_history              .cache/                    .local/                    .profile                   .viminfo
../                        .bash_logout               .config/                   .motd_shown                .python_history
.ansible/                  .bashrc                    .landscape/                .pki/                      .sudo_as_admin_successful
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ cat ~/.
./                         .bash_history              .cache/                    .local/                    .profile                   .viminfo
../                        .bash_logout               .config/                   .motd_shown                .python_history
.ansible/                  .bashrc                    .landscape/                .pki/                      .sudo_as_admin_successful
(ansible-builder-env) eanar@MACHINE:~/eanar/src$ cd ~/ansible-builder-env/lib/python3.12/site-packages/ansible_builder
(ansible-builder-env) eanar@MACHINE:~/ansible-builder-env/lib/python3.12/site-packages/ansible_builder$ grep ">" .
grep: .: Is a directory
(ansible-builder-env) eanar@MACHINE:~/ansible-builder-env/lib/python3.12/site-packages/ansible_builder$ grep -ir ">" .
./containerfile.py:        if self.definition.version >= 3 and not self.definition.options['skip_ansible_check']:
./containerfile.py:        if self.definition.version >= 3 and self.definition.options['relax_passwd_permissions']:
./containerfile.py:        if self.definition.version >= 3 and (final_workdir := self.definition.options['workdir']):
./containerfile.py:        if self.definition.version >= 3 and (uid := self.definition.options['user']):
./containerfile.py:        if self.definition.version >= 3:
./_target_scripts/entrypoint:CUR_USERNAME=$(id -u -n 2> /dev/null || true)  # whoami-free way to get current username, falls back to current uid
./_target_scripts/entrypoint:  function log_debug() { echo "EP_DEBUG: $1" 1>&2; }
./_target_scripts/entrypoint:    function maybe_fail() { echo "EP_FAIL: $1" 1>&2; exit 1; }
./_target_scripts/entrypoint:    function maybe_fail() { echo "EP_WARN: $1" 1>&2; }
./_target_scripts/entrypoint:  if ! getent passwd "${CUR_USERNAME}" &> /dev/null ; then
./_target_scripts/entrypoint:      echo "${CUR_UID}:x:${CUR_UID}:0:container user ${CUR_UID}:${DEFAULT_HOME}:${DEFAULT_SHELL}" >> /etc/passwd
./_target_scripts/entrypoint:    if ! (mkdir -p "${CANDIDATE_HOME}" >& /dev/null && chmod -R ug+rwx "${CANDIDATE_HOME}" >& /dev/null) ; then
./_target_scripts/entrypoint:  echo "${NEWPW}" > /etc/passwd
./_target_scripts/assemble:        bindep -l newline | sort >> /output/bindep/run.txt || true
./_target_scripts/assemble:            bindep -l newline -b epel | sort >> /output/bindep/stage.txt || true
./_target_scripts/assemble:            grep -Fxvf /output/bindep/run.txt /output/bindep/stage.txt >> /output/bindep/epel.txt || true
./_target_scripts/assemble:    if [ $(ls -1 /output/wheels/*whl 2>/dev/null | wc -l) -gt 0 ]; then
./_target_scripts/assemble:      echo "$package" >> /output/packages.txt
./_target_scripts/install-from-bindep:  if [ $(ls -1 /output/wheels/*whl 2>/dev/null | wc -l) -gt 0 ]; then
grep: ./_target_scripts/__pycache__/introspect.cpython-312.pyc: binary file matches
grep: ./_target_scripts/__pycache__/__init__.cpython-312.pyc: binary file matches
./_target_scripts/check_ansible:# Usage: check_ansible <PYCMD>
./_target_scripts/check_ansible:    echo "Usage: check_ansible <PYCMD>"
./_target_scripts/introspect.py:def write_file(filename: str, lines: list) -> bool:
./ee_schema.py:    if schema_version >= 3:
./utils.py:        if main_logger.level > logging.INFO:
./utils.py:        if main_logger.level > logging.DEBUG:
./utils.py:def write_file(filename: str, lines: list) -> bool:
./utils.py:def copy_file(source: str, dest: str, ignore_mtime: bool = False) -> bool:
./utils.py:    elif not ignore_mtime and os.path.getmtime(source) > os.path.getmtime(dest):
./user_definition.py:        if self.version > 2:
./user_definition.py:        if self.version > 1:
grep: ./__pycache__/user_definition.cpython-312.pyc: binary file matches
grep: ./__pycache__/policies.cpython-312.pyc: binary file matches
grep: ./__pycache__/__main__.cpython-312.pyc: binary file matches
grep: ./__pycache__/ee_schema.cpython-312.pyc: binary file matches
grep: ./__pycache__/cli.cpython-312.pyc: binary file matches
grep: ./__pycache__/main.cpython-312.pyc: binary file matches
grep: ./__pycache__/exceptions.cpython-312.pyc: binary file matches
grep: ./__pycache__/constants.cpython-312.pyc: binary file matches
grep: ./__pycache__/colors.cpython-312.pyc: binary file matches
grep: ./__pycache__/containerfile.cpython-312.pyc: binary file matches
grep: ./__pycache__/utils.cpython-312.pyc: binary file matches
grep: ./__pycache__/__init__.cpython-312.pyc: binary file matches
(ansible-builder-env) eanar@MACHINE:~/ansible-builder-env/lib/python3.12/site-packages/ansible_builder$ pip check
No broken requirements found.
(ansible-builder-env) eanar@MACHINE:~/ansible-builder-env/lib/python3.12/site-packages/ansible_builder$ uname -a
Linux MACHINE 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Environment Details:

  • Python Environment:

    • Virtual environment? (Yes)
    • If yes, what tool was used to install ansible-builder? (e.g., python3 -m venv with pip and pipx)
  • System Information:

    • OS: Ubuntu 22.04

Additional Context:

  • The error was observed on both fresh installs of ansible-builder in a virtual environment and when trying to install ansible-builder system-wide.
  • This issue has been persistent through multiple versions of the 3.x.x series, including 3.1.0 and 3.0.1.
  • No other errors were encountered before this, and the problem persists even with minimal configuration.

Thank you for your attention to this issue! Please let me know if you need additional information to help resolve this bug.


Key Points for the Maintainers:

  • The bug appears to be related to type mismatches when comparing version numbers or other numerical values.
  • It’s likely caused by strings being compared to integers, which leads to the TypeError.
  • The error occurs consistently in the ansible-builder build process.
@github-actions github-actions bot added the needs_triage New item that needs to be triaged label Feb 8, 2025
@Shrews
Copy link
Contributor

Shrews commented Feb 8, 2025

Please provide the execution-environment.yml file you used to produce this error.

@Shrews Shrews added needs_info Waiting on feedback. Will be closed. and removed needs_triage New item that needs to be triaged labels Feb 8, 2025
@eanar
Copy link
Author

eanar commented Feb 8, 2025

execution-environment.yml file:

---
version: 3.1.0
dependencies:
  galaxy: requirements.yml
  python: requirements.txt
additional_build_steps:
  prepend:
    - "COPY . /project"

requirements.txt file:

boto
boto3

requirements.yml file:

---
collections:
  - name: amazon.aws

@Shrews
Copy link
Contributor

Shrews commented Feb 10, 2025

Your value for version in the EE file is invalid. It must be an integer. See the docs here.

You should have:

version: 3

@Shrews Shrews closed this as completed Feb 10, 2025
@Shrews Shrews removed the needs_info Waiting on feedback. Will be closed. label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants