Putting it all together – Automating web server deployment

Speaking of automating the setup of a web server, why don't we go ahead and do exactly that? It'll be another simple example, but it will serve you well if we demonstrate more of what Ansible can do. We will set up a Playbook to perform the following tasks:

  1. Install Apache
  2. Start the apache2 service
  3. Copy an HTML file for the new site

First, let's set up the Playbook to simply install Apache. I called mine apache.yml but the name is arbitrary:

---- hosts: all  become: true  tasks:  - name: Install Apache    apt: name=apache2

No surprises here, we've already installed a package at this point. Let's add an additional instruction to have the apache2 service started:

---- hosts: all become: ...

Get Mastering Ubuntu Server - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.