How to use the Ansible Playbook Generator
- 1. Name the play and hostsUse an inventory group such as webservers.
- 2. List the tasksPackages, a user, files to copy, ports to open and a service.
- 3. Dry-run firstRun ansible-playbook with --check before applying it for real.
The default playbook
The starting values create a play named Set up web servers for the webservers group with become: true. It has 6 tasks: install nginx, git and curl with ansible.builtin.package, create a deploy user, copy files/nginx.conf to /etc/nginx/conf.d/app.conf, allow ports 22, 80 and 443 in UFW with a loop, enable UFW with a default deny policy, and start and enable nginx.
The copy task carries notify: Restart nginx, which points at a handler of that name. Handlers run once at the end of the play and only if something changed, so editing the config restarts the service, while a re-run with nothing new leaves it alone.
Good habits the output follows
- Fully qualified names like ansible.builtin.copy avoid clashes between collections and are what current Ansible documentation uses.
- Idempotent tasks: running the playbook twice gives the same result, because each module checks the current state first.
- Port 22 is opened before the firewall is enabled, so you do not lock yourself out of SSH.
- File modes are quoted as "0644" so YAML does not turn them into a decimal number.
UFW tasks need the community.general collection and a Debian or Ubuntu host; on RHEL-family systems use ansible.posix.firewalld instead. Check edits with the YAML validator, and write a matching service unit with the systemd service file generator.
Frequently asked questions
What is an inventory?
A file listing your servers and groups, for example a [webservers] section with host names or IPs. Pass it with -i.
Do I need to install anything on the servers?
No agent is needed. Ansible connects over SSH and needs Python on the managed hosts, which most Linux distributions include.
Is the Ansible Playbook Generator free?
Yes, the Ansible Playbook Generator is free. The first time you generate your first playbook, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.