from typing import Tuple
from typing import Optional
import re


def parse_ansible_version(stdout: str) -> Tuple[str, Optional[str]]:
    """Parse output of 'ansible --version'."""
    # ansible-core 2.11+: 'ansible [core 2.11.3]'
    match = re.match(r"^ansible \[(?:core|base) ([^\]]+)\]", stdout)
    if match:
        return match.group(1), None
    # ansible-base 2.10 and Ansible 2.9: 'ansible 2.x.y'
    match = re.match(r"^ansible ([^\s]+)", stdout)
    if match:
        return match.group(1), None
    return "", "FATAL: Unable parse ansible cli version: %s" % stdout