Skip to content

I am using the ansible_vault module and its construction throws an Exception when used in a textial app #6211

@schnoberts1

Description

@schnoberts1

The code:

"""Trivial Textualize app to test Vault creation."""

from textual.app import App, ComposeResult
from textual.widgets import Static
from ansible import context
from ansible.module_utils.common.collections import ImmutableDict
from ansible_vault import Vault


class VaultTestApp(App):
    """Simple app that creates a Vault instance when 'a' is pressed."""

    def compose(self) -> ComposeResult:
        yield Static("Press 'a' to create a Vault instance, 'q' to quit")

    def on_key(self, event):
        """Handle key press events."""
        if event.key == "a":
            # Create a Vault instance with a dummy password
            vault = Vault("dummy_password")
            self.exit(message=f"Vault instance created: {vault}")
        elif event.key == "q":
            self.exit()


if __name__ == "__main__":
    app = VaultTestApp()
    app.run()%

The exception (when I press 'a'):

ValueError: file descriptor cannot be a negative integer (-1)

I think it's related to this in the Ansible module:

│    29 else:                                                                                                                            │
│    30 │   try:                                                                                                                         │
│    31 │   │   import curses                                                                                                            │
│ ❱  32 │   │   curses.setupterm()                                                                                                       │
│    33 │   │   if curses.tigetnum('colors') < 0:                                                                                        │
│    34 │   │   │   ANSIBLE_COLOR = False                                                                                                │
│    35 │   except ImportError:

Versions

rich==14.2.0
rich-argparse==1.7.1
textual==6.5.0
textual-dev==1.8.0
textual-serve==1.1.3

ansible==11.1.0
ansible-core==2.18.11
ansible-vault==4.1.0

I am running this on a Mac.

(.venv) (base) andy@ice systems % python --version
Python 3.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions