{"id":37634149,"url":"https://github.com/juanje/ansible-play-template","last_synced_at":"2026-01-16T11:01:08.630Z","repository":{"id":46814579,"uuid":"254474714","full_name":"juanje/ansible-play-template","owner":"juanje","description":"A simple template for develop an Ansible playbook using molecule and testinfra for testing.","archived":false,"fork":false,"pushed_at":"2023-01-24T23:29:30.000Z","size":17,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-12T13:02:26.140Z","etag":null,"topics":["ansible","ansible-playbook","docker","molecule","pytest","template","testinfra"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juanje.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}},"created_at":"2020-04-09T20:44:35.000Z","updated_at":"2020-04-11T12:39:56.000Z","dependencies_parsed_at":"2023-02-14T02:31:13.887Z","dependency_job_id":null,"html_url":"https://github.com/juanje/ansible-play-template","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/juanje/ansible-play-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanje%2Fansible-play-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanje%2Fansible-play-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanje%2Fansible-play-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanje%2Fansible-play-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juanje","download_url":"https://codeload.github.com/juanje/ansible-play-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juanje%2Fansible-play-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","ansible-playbook","docker","molecule","pytest","template","testinfra"],"created_at":"2026-01-16T11:01:08.414Z","updated_at":"2026-01-16T11:01:08.594Z","avatar_url":"https://github.com/juanje.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Playbook template\n\nThis is just a simple template for start an [Ansible](https://github.com/ansible/ansible/) playbook.\nThe aim of this template is to have the minimum functional playbook so you can start to build your own.\n\nThe template is configured to run a simple task (install git) and to test if the task has done its job correctly, by using [molecule](https://molecule.readthedocs.io).\n\n**Molecule** is a testing framework for **Ansible**. It also has been configured to use [Testinfra](https://testinfra.readthedocs.io) for the actual tests and [Docker](https://docs.docker.com/get-started/overview/) to run the instances where the tasks and tests will run.\n\nAll of this can be changed, but I think it's pretty straightforward configuration to start and it's working **out of the box** here.\n\n## Use it\n\nIn order to start with this playbook and use all its power you'll need to install a few things:\n* **Ansible**\n* **Docker**\n* **Molecule**\n* **Pytest**\n* **Testinfra**\n* **Pylint**\n* **flake8**\n\nYou can disable the linting and avoid installing **pylint** and **flake8**, but I don't recommend it. It's always better to code with style ;-)\n\nIf you've **Python** and **Pip** (Python package manager) installed you can install most of this by doing:\n```\npip install -r requirements.txt\n```\n\nOnce you have all the dependencies installed you can play with molecule, to see that everything is OK.\nFirst, let's see the instances we have configured and their status:\n```\n$ molecule list\nInstance Name  Driver Name  Provisioner Name  Scenario Name  Created  Converged\n-------------  -----------  ----------------  -------------  -------  -----------\nubuntu1804     docker       ansible           default        false    false\n```\n\nNow, let's runs the Ansible tasks and the tests:\n```\n$ molecule test\n```\n\nThis should run all the steps that molecule has configured:\n* **Lint** (lint all the Ansible files and Python tests)\n* **Create** (the instance, the Docker container)\n* **Prepare** (make sure Python is installed)\n* **Converge** (provision the instance with the Ansible tasks)\n* **Verify** (run the **testinfra** tests)\n* **Destroy** (stop and remove the Docker container)\n\n## Structure\n\nThis is the minimal structure I've found to create a playbook with molecule's tests. You can add more files and directories as you need, but with the current structure you can run the tasks and the tests with no changes.\n\n```\n├── hosts\n├── LICENSE\n├── molecule\n│   └── default\n│       ├── converge.yml\n│       ├── molecule.yml\n│       ├── prepare.yml\n│       └── tests\n│           ├── conftest.py\n│           └── test_default.py\n├── playbook.yml\n└── README.md\n```\n\nThe important files (the one you want to start editing) are these two:\n```\n├── molecule\n│   └── default\n│       └── tests\n│           └── test_default.py\n├── playbook.yml\n```\n* [playbook.yml](playbook.yml) -\u003e Where you're going to puts your tasks.\n* [test_default.py](molecule/default/tests/test_default.py) -\u003e Where you're going to put your tests.\n\nRight now this is configured to run the **tasks** and **tests** on a **Docker** image of **Ubuntu 18.04**. But if can be changed at the file [molecule.yml](molecule/default/molecule.yml):\n```\n├── molecule\n│   └── default\n│       ├── molecule.yml\n\n```\n\n## Testing\n\nFor the tests you can use different frameworks (Ansible, InSpec, Goss, TestInfra...), but I've configured the project to use **TestInfra**, which is a extension of Pytest to test systems (servers and such).\n\nAs an example, there is a simple test that checks if a specific binary file is in the correct place in the system. I think this is a better test than check for specific package to be installed because that way you can be sure that you have that binary available, no matter what distribution you are at or what method you used to install it.\n\nFor me, create tests for **playbooks**, **roles** or **collections** should assure some requirements and allow us to **refactor** or change our plays and tasks safely.\n\nIn order to test the plays you need to *create* and *converge* the instance, then you can *verify* (run the tests). You can just run `molecule test` each time, but it'll *destroy* and *create* the instance each time, so it takes some time.\n\nI recommend you to run that command once in a while, but you can run just `molecule converge` to run the tasks and the run `molecule verify` each time you make a change.\n\n```\n$ molecule converge\n.... (It'll run the Ansible tasks)\n# Do some changes\n\n$ molecule verify\n... (It'll run the tests and see the results)\n```\n\nBut don't forget to run `molecule converge` to run the Ansible tasks each time you change them, or they won't be reflected at the instance.\n\n## Versions\n\nThis template is tested with the following versions:\n\n|                       |                   |\n| --------------------- | ----------------- |\n| **Ansible**           |  **2.9.6**        |\n| **Molecule**          |  **3.0.2**        |\n| **TestInfra**         |  **3.2.1**        |\n| **Docker container**  |  **Ubuntu 18.04** |\n\n\n\n## License\n\n|                |                                           |\n| -------------- | ----------------------------------------- |\n| **Author:**    | Juanje Ojeda (\u003cjuanje.ojeda@gmail.com\u003e)   |\n| **Copyright:** | Copyright (c) 2020 Juanje Ojeda           |\n| **License:**   | Apache License, Version 2.0               |\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanje%2Fansible-play-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuanje%2Fansible-play-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuanje%2Fansible-play-template/lists"}