Ansible Pygments

0.1.2 · active · verified Thu Apr 16

Ansible Pygments provides a Pygments lexer specifically designed to highlight Ansible output. It can be integrated into any application that uses Pygments for syntax highlighting, such as Sphinx documentation. The lexer is globally registered under the name `ansible-output` and also offers a Pygments style. The project is actively maintained with regular, typically minor, releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `ansible-output` lexer with Pygments to highlight a string containing Ansible output and render it as HTML.

from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

ansible_output = """
[WARNING]: Unable to find '/nosuchfile' in expected paths (use -vvvvv to see paths)
ok: [localhost] => {
    "msg": "Hello from Ansible!"
}
"""

try:
    lexer = get_lexer_by_name('ansible-output')
    formatter = HtmlFormatter()
    highlighted_html = highlight(ansible_output, lexer, formatter)
    print(highlighted_html)
except Exception as e:
    print(f"Error highlighting: {e}")
    print("Make sure 'ansible-pygments' and 'Pygments' are installed.")

view raw JSON →