# Testing Infrastructure Code by Executing Its Real Expressions

DevFeed: [Testing Infrastructure Code by Executing Its Real Expressions](<https://devfeed.tech/articles/testing-infrastructure-code-by-executing-its-real-expressions-34115.md>)

Original publisher: [Read original article](<https://philipptheserver.com/posts/testing-real-expressions/>)

Author: Philipp Lehmann (philipp.lehmann@gruppe.ai)

Published: 2026-08-28T07:00:00Z

Content type: tutorial

Language: en

Sources: [Philipp Lehmann](<https://devfeed.tech/sources/philipp-lehmann.md>)

Topics: [Ansible](<https://devfeed.tech/topics/ansible.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Pytest](<https://devfeed.tech/topics/pytest.md>), [Ansible Roles](<https://devfeed.tech/topics/ansible-role.md>)

Tags: [ansible](<https://devfeed.tech/tags/ansible.md>), [ci-cd](<https://devfeed.tech/tags/ci-cd.md>), [code](<https://devfeed.tech/tags/code.md>), [infrastructure](<https://devfeed.tech/tags/infrastructure.md>), [infrastructure-as-code](<https://devfeed.tech/tags/infrastructure-as-code.md>), [pytest](<https://devfeed.tech/tags/pytest.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This article explains how to test Ansible infrastructure code by rendering the shipped Jinja expression through Ansible's actual templating machinery. It recommends extracting the expression from the role file, using realistic fixture variables, and asserting on the rendered result instead of duplicating the computation in Python.

## Source excerpt

Ansible Templar in pytest: render the shipped combine(recursive=True) expression from defaults/main.yml instead of a shallow Python paraphrase.