# Molecule/testinfra

**URL:** <https://forum.ansible.com/t/molecule-testinfra/27389>\
**Category:** Ansible Project\
**Created:** [April 26, 2018, 6:10pm UTC](https://forum.ansible.com/t/molecule-testinfra/27389 "2018-04-26T18:10:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [April 26, 2018, 6:10pm UTC](https://forum.ansible.com/t/molecule-testinfra/27389/1 "2018-04-26T18:10:10Z")

</div>

Is anyone using molecule/testinfra to test real infrastructure (verifying things ansible has managed)? The unit testing of playbooks is awesome but how would I use the framework to test real things on real systems?

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [April 27, 2018, 1:13pm UTC](https://forum.ansible.com/t/molecule-testinfra/27389/2 "2018-04-27T13:13:36Z")

</div>

You wouldn’t.

You’re supposed to test things before you deploy them.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 27, 2018, 1:28pm UTC](https://forum.ansible.com/t/molecule-testinfra/27389/3 "2018-04-27T13:28:30Z")

</div>

You can use Ansible itself for testing 'existing state':

- use unprivileged users so any 'change' would fail and that failure  
would tell you it is not the expected state. i.e service: name=apache  
state=started

- check mode/diff are also helpful when combined with assert/fail

- it is good to model it in a TDD form, have one person create the  
playbook the sets the state, another one that verifies the state, this  
requires a good spec on 'expected state'

It should be simple for QA to audit and map the tasks and plays to the  
test cases.
