47 lines
1.0 KiB
YAML
47 lines
1.0 KiB
YAML
---
|
|
- name: Demo Playbook - Install Nginx and Serve Hostname Page
|
|
hosts: all
|
|
become: true
|
|
|
|
tasks:
|
|
- name: Ensure apt cache is updated
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
cache_valid_time: 3600
|
|
|
|
- name: Install nginx
|
|
ansible.builtin.apt:
|
|
name: nginx
|
|
state: present
|
|
|
|
- name: Create index.html with hostname
|
|
ansible.builtin.copy:
|
|
dest: /var/www/html/index.html
|
|
content: |
|
|
<html>
|
|
<head><title>Demo</title></head>
|
|
<body>
|
|
<h1>Hostname: {{ inventory_hostname }}</h1>
|
|
</body>
|
|
</html>
|
|
owner: www-data
|
|
group: www-data
|
|
mode: "0644"
|
|
|
|
- name: Allow HTTP through firewall
|
|
community.general.ufw:
|
|
rule: allow
|
|
port: "80"
|
|
proto: tcp
|
|
|
|
- name: Enable ufw
|
|
community.general.ufw:
|
|
state: enabled
|
|
enabled: true
|
|
|
|
- name: Ensure nginx is running
|
|
ansible.builtin.service:
|
|
name: nginx
|
|
state: started
|
|
enabled: true
|