Ansible collection that calls the xAI API (api.x.ai) via the official xai-sdk Python package.
Grok is the text model family on that API. The same API and key also cover image, video, and voice models. One API, not two.
ansible-galaxy collection install git+https://github.com/aknochow/ansible-xai.gitOr develop locally:
uv sync --extra devOne key for api.x.ai. Set GROK_API_KEY in the environment. The module also accepts XAI_API_KEY (the xAI SDK name) and optional ANSIBLE_GROK_API_KEY via env_fallback.
Never log or commit API keys.
- name: Ask a Grok model
aknochow.xai.chat:
model: grok-4.7
max_tokens: 256
api_key: "{{ lookup('env', 'GROK_API_KEY') }}"
messages:
- role: user
content: "Hello"
register: grokuv run pytest