DevOps

Ansible Playbook Scaffolder

Generate an Ansible playbook and role skeleton with idempotent module usage, handlers, check mode support and the patterns that keep a playbook safe to run repeatedly.

Last reviewed by the Radiatus Cloud team

Playbook appears here.

Want this automated for your stack?

We build CI/CD, Kubernetes & IaC pipelines that scale.

Talk to an engineer

Idempotence is a property of the modules you choose

Running a playbook twice should change nothing the second time. Ansible modules are written to make that true: the package module checks whether a package is installed before installing, and the lineinfile module checks whether the line is present. The command and shell modules cannot do this, because Ansible has no idea what an arbitrary command does. Every shell task is a hole in the idempotence of a playbook, which is why they need a changed_when or a creates argument to tell Ansible when they actually did something.

Handlers batch the restarts

A playbook that changes three configuration files and restarts the service in each task restarts it three times. Handlers exist to solve this: a task notifies a handler, and the handler runs once at the end of the play regardless of how many tasks notified it. This is not merely tidier, it is the difference between a rolling deploy that restarts each service once and one that restarts it repeatedly while traffic is flowing.

Check mode is only useful if the playbook supports it

Running with the check flag reports what would change without changing it, which is the closest thing to a dry run. It works for well written module tasks and breaks for shell tasks, which either run anyway or get skipped and then make every dependent task report incorrectly. Marking read only commands with check_mode false and adding explicit changed_when conditions is what makes the dry run trustworthy, and an untrustworthy dry run is worse than none.

Related tools

Frequently Asked Questions

Why should I avoid the shell and command modules?

Because Ansible cannot tell whether they changed anything, so they report changed every run and break both idempotence and check mode. Use a purpose built module where one exists, and where it does not, add creates, removes or an explicit changed_when.

What is the difference between a handler and a task?

A handler runs only when notified and only once at the end of the play, however many tasks notified it. That is what stops a playbook restarting a service once per changed configuration file.

How do I make a playbook safe to run repeatedly?

Use modules that describe desired state rather than commands that perform actions, add creates or changed_when to any shell task, and test with --check and --diff. A playbook that reports changes on a second identical run is not idempotent and will eventually do something unintended.

Should I use roles or a single playbook?

Roles for anything reused or longer than a few dozen tasks. The directory structure is a convention Ansible understands, so variables, handlers, files and templates are found automatically without explicit includes, and the role becomes testable in isolation.

How should secrets be handled?

Ansible Vault for values committed to the repository, or an external secret manager looked up at run time. Never plain text in a variable file, and set no_log on any task that handles a secret, or the value appears in the output and in the CI logs.

Privacy & Security

Everything runs in your browser; nothing is uploaded.

Data: None
Client-side-Side
Active
v1.0

How to Use

Choose the tasks your playbook needs to generate a role structure and playbook.

Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.