{"id":16777571,"url":"https://github.com/rndmh3ro/ansible-test-framework","last_synced_at":"2025-08-27T22:11:45.583Z","repository":{"id":151220094,"uuid":"47578001","full_name":"rndmh3ro/ansible-test-framework","owner":"rndmh3ro","description":"Framework to test Ansible roles with serverspec on multiple systems","archived":false,"fork":false,"pushed_at":"2022-03-07T09:34:53.000Z","size":28,"stargazers_count":13,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T18:12:08.204Z","etag":null,"topics":["ansible","docker","test-kitchen","testing","travis"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rndmh3ro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-07T20:41:30.000Z","updated_at":"2022-03-07T09:34:57.000Z","dependencies_parsed_at":"2023-06-26T10:00:52.661Z","dependency_job_id":null,"html_url":"https://github.com/rndmh3ro/ansible-test-framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndmh3ro%2Fansible-test-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndmh3ro%2Fansible-test-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndmh3ro%2Fansible-test-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndmh3ro%2Fansible-test-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rndmh3ro","download_url":"https://codeload.github.com/rndmh3ro/ansible-test-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248292965,"owners_count":21079546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","docker","test-kitchen","testing","travis"],"created_at":"2024-10-13T07:25:10.088Z","updated_at":"2025-04-10T20:41:44.508Z","avatar_url":"https://github.com/rndmh3ro.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Testing Ansible Roles\n\n**Please note that this setup (probably still) works, however the default approach to testing within Ansible is with Molecule!**\n\nThis framework provides the necessary files and configurations to easily setup your environment for testing ansible-roles.\nIt uses test-kitchen, docker (or vagrant) and serverspec to test your roles on multiple operating systems.\nIt also supports automated travis-tests out of the box.\n\n## Prerequesites\n\nInstall the following software:\n\n- Git\n- Ruby\n- Docker\n\nOptionally:\n- VirtualBox\n- Vagrant\n\n## Docker images\n\nThis setup user custom [docker images](https://github.com/rndmh3ro/docker-ansible).\nThese docker images only derive from the base images as they have Ansible pre-installed, thus saving the time to install it!\n\n## Setup\n\nCreate a directory for your role you want to test (called `ansible_role` in the following example).\n**The name directory and the name of the role have to be the same!**\nGit-clone the testing-framework into your newly created directory, change into it and delete the now useless .git directory:\n```\n# basic setup\nmkdir ansible_role\ngit clone https://github.com/rndmh3ro/ansible-test-framework ansible_role/\ncd ansible_role/\nrm -fr .git/\n```\n\nCreate an empty role with `ansible-galaxy`.\nRun inside your role-directory, replace `ansible_role` with the name you gave the directory.\n\n```\n# create empty ansible role\nansible-galaxy init --force ../ansible_role\n```\n\nInstall test-kitchen, serverspec, the provisioner, driver and all its dependencies, with the help of [bundler]:\n```\n# Install software and dependencies\ngem install bundler\nbundle install\n```\n\nCustomize your testing-setup.\nReplace the default name `ansible-test-framework` with the name of your role (in this example `ansible_role`) in two places:\n- `default.yml` -\u003e replacement should be in the `roles_path`.\n- `.kitchen.yml` -\u003e replacement should be the first item after `roles`.\n- `.travis.yml` -\u003e replacement should be under `# syntax-check`, `# Test role.` and `# test role idempotence.`\n\nYou can also use this `sed`-command to replace the occurences.\nJust replace `ansible_role` in the command with the name of your role.\n\n```\n# replace ansible-test-framework with your role-name in:\nsed -i 's/ansible-test-framework/ansible_role/g' default.yml .kitchen.yml .kitchen.vagrant.yml .travis.yml\n```\n\n## Write the role and tests\n\nWrite your ansible role and tests now.\nThere's already a file called *test_spec.rb* where you can write your tests in and the spec_helper is configured for serverspec.\n\nFor more help writing tests and using serverspec, read the docs:\n- http://kitchen.ci/docs/getting-started/writing-server-test\n- https://github.com/neillturner/kitchen-ansible#test-kitchen-serverspec\n\n## Testing with Docker\n\nYou will have to install Docker on your system. See [Get started](https://docs.docker.com/) for a Docker package suitable to for your system.\n\nYou can test single machines, a set of machines or all at once. See the following examples or take a look at the test-kitchen [docs]().\n\nIf you are using [Docker for Windows](https://docs.docker.com/docker-for-windows/install/), make sure you are using the correct [socket](https://github.com/test-kitchen/kitchen-docker#socket) settings.\n\n```\n# fast test on one machine\nbundle exec kitchen test ansible-centos7-ansible-latest\n\n# test on all machines in parallel\nbundle exec kitchen test -c\n\n# test all ubuntu machines\nbundle exec kitchen test ubuntu\n```\n\n## Testing with Virtualbox\nYou can also use vagrant and Virtualbox or VMWare to run tests locally.\nYou will have to install Virtualbox and Vagrant on your system.\nSee [Vagrant Downloads](http://downloads.vagrantup.com/) for a vagrant package suitable for your system.\n\n```\n# fast test on one machine\nKITCHEN_YAML=\".kitchen.vagrant.yml\" bundle exec kitchen test ansible-ubuntu-1604\n\n# test on all machines in parallel\nKITCHEN_YAML=\".kitchen.vagrant.yml\" bundle exec kitchen test -c\n\n# test all ubuntu machines\nKITCHEN_YAML=\".kitchen.vagrant.yml\" bundle exec kitchen test ubuntu\n```\n\n## Tips\n\n* While developing roles it can be cumbersome to always destroy and recreate the machines if a test or the role fails at some point.\nTo circumvent this, you can create and then converge the machine. If the role fails during converging, you can simply run the converge again:\n\n```\n# for development\n\nbundle exec kitchen create ansible-latest-ubuntu-1604\nbundle exec kitchen converge ansible-latest-ubuntu-1604\n\n# ... run fails, change role, converge again\n\nbundle exec kitchen converge ansible-latest-ubuntu-1604\n```\n\n* If your role takes a long time to run and you want to debug a specific task, you can run the converge with the help of an environment variable like this:\n\n```\nANSIBLE_EXTRA_FLAGS='--start-at-task=\"ansible_role | name of last working instruction\"' bundle exec kitchen converge\n```\n\nReplace *ansible_role | name of last working instruction* with the name of the task you want to start at, so you can skip others.\n\n* Similary if you want to skip certain tasks, you can use the environment variable like this:\n\n```\nANSIBLE_EXTRA_FLAGS='--skip-tags=beginning' bundle exec kitchen converge\n```\n\n[test-kitchen]: https://github.com/test-kitchen/test-kitchen\n[vagrant]: https://www.vagrantup.com/\n[VirtualBox]: https://www.virtualbox.org/\n[rake]: https://github.com/ruby/rake\n[serverspec]: http://serverspec.org/\n[kitchen-ansible]: https://github.com/neillturner/kitchen-ansible\n[kitchen-vagrant]: https://github.com/test-kitchen/kitchen-vagrant\n[kitchen-sync]: https://github.com/coderanger/kitchen-sync\n[kitchen-transport-rsync]: https://github.com/unibet/kitchen-transport-rsync\n[thor-foodcritic]: https://github.com/reset/thor-foodcritic\n[hardening.io]: http://hardening.io/\n[git]: https://www.git-scm.com/\n[bundler]: http://bundler.io/\n[docs]: http://kitchen.ci/docs/getting-started/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frndmh3ro%2Fansible-test-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frndmh3ro%2Fansible-test-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frndmh3ro%2Fansible-test-framework/lists"}