A lab playbook sets up Apache with HTTPS on Debian hosts in one play. Which steps does it run, in which order, and which control-flow tool does each step use?
Fail fast if the host is unsuitable (fail + when), install packages (apt), start services (loop), enable SSL and the HTTPS site (notify), copy certificate and key in a block with rescue, write the page, remove any .htaccess, and restart Apache once at the end (handler).
* One play, every tool from this topic: when, loop, notify, block/rescue and a handler. *
The play targets the debian group with become: true and loads its settings from a variables file (packages, services, web_service, ssl_cert_dir, ssl_key_dir, web_root, min_ram_mb). In order:
- Fast fail check:
ansible.builtin.failwith awhenon RAM and distribution. - Packages:
aptinstallsapache2,opensslandca-certificates(state: latest,update_cache: yes). - Services:
servicewithloop: "{{ services }}", started and enabled. - SSL module:
shell: a2enmod ssl, notifyingRestart web service. - Virtual host:
copythe HTTPS site file to/etc/apache2/sites-available/, thenshell: a2ensite itia-lhe-ssl.conf, both notifying the handler. - Certificates: a
blockthat creates the two SSL directories and copies certificate and key with aloopover dictionaries; itsrescueprints a message. - Content:
copywithcontent:writesindex.htmlfrom facts. - No auth:
file: state: absentremoves.htaccess. - Handler:
Restart web servicerestartsapache2, once, after all tasks.
The result is checked with curl -k https://<host>, which should return the generated page.
Go deeper:
SSL/TLS strong encryption: how-to (Apache httpd docs) โ what a minimal HTTPS virtual host needs.