Chapter 11: Ansible Introduction
11.5 Playbook — Nginx welcome for badge API
# playbooks/web_welcome.yml
- name: Configure badge API welcome web
hosts: badge-api_web
become: true
tasks:
- name: Ensure Nginx package is installed
ansible.builtin.yum:
name: nginx
state: present
# On Ubuntu use ansible.builtin.apt with update_cache: true
- name: Deploy welcome index
ansible.builtin.copy:
dest: /usr/share/nginx/html/index.html
mode: "0644"
content: |
<!DOCTYPE html>
<html><body>
<h1>Instagram-style badge API</h1>
<p>Lab welcome page for the badge API course lab.</p>
</body></html>
- name: Ensure Nginx is started and enabled
ansible.builtin.service:
name: nginx
state: started
enabled: true
Run:
ansible-playbook -i inventory/hosts.ini playbooks/web_welcome.yml
Steps — first playbook success
- Confirm SSH to the target works with the inventory user.
- Create
inventory/hosts.iniandplaybooks/web_welcome.yml. - Match package module to the OS (Amazon Linux family →
yum/dnfmodule as appropriate; Ubuntu →apt). ansible-playbook …and read the recap:ok/changed/failed.- From your laptop:
curl -I http://TARGET:80(shop counter 80) — expect success if SG allows your IP (AWS course SG skills). - Run the playbook a second time — expect mostly
ok, littlechanged.
What you see: Browser or curl shows the badge API welcome heading. Second run is boring — that is success.
Deep Nginx tuning, TLS, and multi-site hosting stay in the AWS Cloud web chapters — here Nginx is only a configuration target.
Ravindra Bagale's Tip
Path /usr/share/nginx/html distro-nuusar thoda vegla asu shakto. Fail zala tar nginx -V / distro doc check kara — guess karu nako. Lakshat theva!