ansible-navigator Documentation

repository·main·Indexed 19 days ago

https://github.com/ansible/ansible-navigator

A text-based user interface (TUI) for the Red Hat Ansible Automation Platform. It provides an interactive way to run playbooks, explore collections, manage inventories, and view documentation, defaulting to containerized execution environments using Podman or Docker for consistency.

Tokens
10.6K
Snippets
39
Records
61
Agent score
66%

What's inside ansible-navigator

  1. Overview of ansible-navigator

    main

    ansible-navigator is a command-line tool and a text-based user interface (TUI) designed for managing the lifecycle of Ansible content. It provides a unified interface for:

    • Creating and reviewing Ansible content (inventories, playbooks, collections, and documentation).
    • Running and troubleshooting Ansible content.
    • Managing container images known as Execution Environments (EEs).
  2. Map ansible-navigator commands to Ansible commands

    main
    ansible-navigator provides subcommands that map to standard Ansible CLI tools. Depending on the tool, you can invoke them directly via a dedicated ansible-navigator subcommand, or use the exec subcommand to run the original Ansible command within an execution environment (EE).
  3. Understand the `ansible-navigator` configuration hierarchy

    main

    Settings in ansible-navigator are applied hierarchically. If a setting is defined in multiple places, the last one in this list takes precedence:

    1. Default internal values
    2. Values from a settings file
    3. Values from environment variables
    4. Flags and arguments specified on the command line
    5. Commands issued via : within the Text User Interface (TUI)
  4. Understand ansible-navigator output modes

    main

    ansible-navigator operates in two distinct modes:

    1. interactive (default): A curses-based text-based user interface (TUI) that allows you to "zoom in" on data in real time, filter results, and navigate between Ansible components.
    2. stdout: A non-interactive mode that does not use curses. It returns output directly to the terminal's standard output stream, mimicking the behavior of standard Ansible commands.

    You can switch to stdout mode using the --mode stdout (or -m stdout) flag or by configuring the mode setting in your configuration file.

  5. Review playbook artifacts

    main

    ansible-navigator generates a JSON artifact for every playbook run (e.g., site-artifact-TIMESTAMP.json). These files contain detailed task information and stdout.

    You can review these artifacts using:

    • The CLI: ansible-navigator replay <filename>
    • The TUI: Use the :replay <filename> command.

    Artifact writing and naming conventions can be customized in the settings file.

    ansible-navigator replay site-artifact-2021-06-02T16:02:33.911259+00:00.json
  6. Run ansible-test inside an execution environment

    main

    You can run the ansible-test utility from within an execution environment without having it installed locally by using the exec subcommand.

    $ cd  ./collections/ansible_collections/ansible/utils/
    $ ansible-navigator exec -- ansible-test sanity --python 3.10
  7. Configure `ansible.cfg` for Execution Environments

    main

    When using an execution environment (EE), the easiest way to provide an ansible.cfg file is to place it in the project directory adjacent to your playbook. ansible-navigator automatically mounts the playbook directory into the EE, allowing Ansible to find the configuration.

    If your ansible.cfg is located elsewhere, you must:

    1. Set the ANSIBLE_CONFIG environment variable to the file path.
    2. Specify the directory containing the file as a custom volume mount using the execution-environment-volume-mounts setting.
  8. Define volume mounts via environment variables

    main

    When defining volume mounts using the ANSIBLE_NAVIGATOR_EXECUTION_ENVIRONMENT_VOLUME_MOUNTS environment variable, you must use a semicolon (;) as a delimiter because the standard colon (:) is used within the mount definition itself.

    export ANSIBLE_NAVIGATOR_EXECUTION_ENVIRONMENT_VOLUME_MOUNTS /tmp/1:/tmp/1\;/tmp/2:/tmp/2:Z
    ansible-navigator exec
  9. Pass ansible-playbook parameters to ansible-navigator

    main

    Any parameters that are not direct ansible-navigator options will be passed through to the underlying ansible-playbook command. You can provide these inline or use the -- delimiter to separate ansible-navigator arguments from ansible-playbook arguments.

    $ ansible-navigator run site.yml --forks 15
    $ ansible-navigator run site.yml -- --forks 15
  10. Install ansible-navigator

    main

    You can install ansible-navigator using pip. It is recommended to install it with the ansible-core extra to ensure compatibility.

    By default, ansible-navigator uses a container runtime (podman or docker, whichever is found first) to run Ansible within an execution environment (a pre-built container image containing ansible-core and collections).

    To disable the execution environment and run Ansible directly on your host system, use the --execution-environment false flag. In this mode, you must ensure ansible-core and all required collections are manually installed on your system.

    pip3 install 'ansible-navigator[ansible-core]'
    ansible-navigator --help
  11. Run complex commands inside an execution environment

    main

    To execute complex piped commands inside an execution environment, use the -- delimiter. Everything following the -- is passed directly into the execution environment.

    $ ansible-navigator exec -- ansible --version | head -n 1 | awk -F '\\[|\\\]|\\s' '{print $4}'