Add webserver and configure

From MyWiki
Jump to: navigation, search

Ref : https://www.digitalocean.com/community/tutorials/configuration-management-101-writing-ansible-playbooks

---
- hosts: all
  become: true
  vars:
    doc_root: /var/www/example
  tasks:
    - name: Update apt
      apt: update_cache=yes
 
    - name: Install Apache
      apt: name=apache2 state=latest
 
    - name: Create custom document root
      file: path={{ doc_root }} state=directory owner=www-data group=www-data
 
    - name: Set up HTML file
      copy: src=index.html dest={{ doc_root }}/index.html owner=www-data group=www-data mode=0644
 
    - name: Set up Apache virtual host file
      template: src=vhost.tpl dest=/etc/apache2/sites-available/000-default.conf
      notify: restart apache
  handlers:
    - name: restart apache
      service: name=apache2 state=restarted