# Using serverspec with ansible

**URL:** <https://forum.ansible.com/t/using-serverspec-with-ansible/23352>\
**Category:** Ansible Project\
**Created:** [December 31, 2016, 4:36am UTC](https://forum.ansible.com/t/using-serverspec-with-ansible/23352 "2016-12-31T04:36:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Steffen](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@Dan\_Steffen](https://forum.ansible.com/u/Dan_Steffen)\
**Post date:** [December 31, 2016, 4:36am UTC](https://forum.ansible.com/t/using-serverspec-with-ansible/23352/1 "2016-12-31T04:36:41Z")

</div>

Hello,

I would like to use serverspec with ansible so I can test if the services a running and listing, but I didn’t find any informationen about how I can use it, especially how I call the test in the playbook.  
I would very thankful if someone can give me please some information about the usage.  
best regards  
Dan

---

<div class="post-metadata">

**Author:** ![Jeremy\_Young](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@Jeremy\_Young](https://forum.ansible.com/u/Jeremy_Young)\
**Post date:** [January 3, 2017, 1:58pm UTC](https://forum.ansible.com/t/using-serverspec-with-ansible/23352/2 "2017-01-03T13:58:01Z")

</div>

For what it’s worth I tend to like the Testinfra project a bit more:

[http://testinfra.readthedocs.io/en/latest/](http://testinfra.readthedocs.io/en/latest/)

I try and follow the practice of “cattle not pets” as much as possible and with all of the infrastructure I manage in AWS don’t have a use case for testing a set of servers that are long-lived. I do, though, make heavy use of [Packer](https://www.packer.io/docs/) and Ansible for creating an image from which I’ll deploy my VMs. I’ve used Serverspec before as a final provisioning step, started by a shell script and executing something like this to perform my tests  
`cd tests/directory bundle exec rake spec`

Doing it that way ensures that my AMI is only created by Packer if all of my tests pass.

That said, I think it’s important to not duplicate your Ansible code just to have tests written in Serverspec or Testinfra. Ansible is purposely built to configure the desired state of your server/image. If all you want is to make sure a service is running and/or listening then re-run your Ansible playbook. If you’re running these tests out-of-band from, say, Nagios or on a security team to validate the configuration of your image, checking whether a service is running with Serverspec or Testinfra makes sense.
