O'Reilly logo

Learning Ansible 2 - Second Edition by Fabio Alessandro Locati

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Publishing a website

Since our website will be a simple, single page website, we can easily create it and publish it using a single Ansible task. To make this page a little bit more interesting, we will create it from a template that will be populated by Ansible with a little data about the machine. The script to publish it will be called deploy_website.yaml and will have the following content:

--- 
- hosts: all 
  remote_user: ansible 
  tasks: 
  - name: Ensure the website is present and updated 
    template: 
      src: index.html.j2 
      dest: /var/www/html/index.html 
      owner: root 
      group: root 
      mode: 0644 
    become: True 

Let's start with a simple template that we will call index.html.j2:

<html> 
    <body> 
        <h1>Hello World!</h1> 
    </body> 
</html> 

Now we can test our website deployment ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required