Testing playbooks with 3rd party roles and custom tasks
wilkko opened this issue · 7 comments
Is it possible to write and run tests that would test playbooks that have 3rd party roles and custom tasks? Assumption with ansible_spec seems to be that all the specs are within roles.
Assumption with ansible_spec seems to be that all the specs are within roles.
@wilkko I'm not the maintainer, but your assumption appears correct. If you're trying to test playbooks that require external roles, simply script fetching the external roles prior to running the tests. As long as the roles do not have files matching spec/*_spec.rb
, then no Serverspec tests will be run for those roles. (That's good, because otherwise including the external roles would cause the tests to fail.)
I designed directory that spec are within roles.(e.g. roles/)/spec/*_spec.rb)
So, 3rd party roles and custom tasks is not run test.
But If you use include
in ansible playbook, ansible_spec detect include
.
I hope it will be helpful to you.
# site.yml (playbook)
- name: Ansible-Sample-TDD
hosts: server
user: root
roles:
- mariadb #<= test target (roles/mariadb/spec/*_spec.rb)
- include: nginx.yml
# nginx.yml (playbook)
- name: Ansible-Nginx
hosts: web
user: nginx
roles:
- nginx # <= test target (roles/nginx/spec/*_spec.rb)
I meant that it would be nice to detect ServerSpec configuration based on Ansible inventory and playbooks. Then run relevant serversspecs against relevant hosts. Much like they do here: https://github.com/redhat-cip/openstack-serverspec/blob/master/Rakefile
@wilkko You can add as many tasks as you want to the Rakefile
—just write additional Serverspec tests for your third-party roles, then include them in the Rakefile
under a different task. If you want, you can even update the task :all =>
line to include the ansible_spec
tests and your custom ones.
Make sense?
I guess so :) Thanks.
Hey @wilkko, just came across this today, sounds like what you're talking about:
- https://github.com/ehaselwanter/kitchen-sharedtests/
- example here: https://github.com/hardening-io/tests-os-hardening
- original role here: https://github.com/hardening-io/ansible-os-hardening/
Looks like the kitchen-sharedtests
gem will be helpful to you! Would necessitate that the maintainers of the third-party roles you're talking about play along and create separate test repos, so you'll probably have to stick to the earlier idea of writing your own tests, but at least now you can reuse the tests you write across projects.