Advertisement
PandaAcademy

Nginx playbook - final

Mar 8th, 2024 (edited)
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.82 KB | None | 0 0
  1. ---
  2. - name: Install Nginx
  3.   hosts: all
  4.   connection: local
  5.   become: yes
  6.   tasks:
  7.     - name: Update apt package index
  8.       apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
  9.  
  10.     - name: Install Nginx
  11.       apt:
  12.         name: nginx
  13.         state: present
  14.  
  15.     - name: Ensure Nginx is running and enabled
  16.       systemd:
  17.         name: nginx
  18.         state: started
  19.         enabled: yes
  20.  
  21.     - name: Copy Nginx server block files
  22.       template:
  23.         src: "templates/site.conf.j2"
  24.         dest: "/etc/nginx/sites-enabled/{{ item }}.conf"
  25.       loop:
  26.        - "127.0.0.1"
  27.         - "127.0.0.2"
  28.         - "127.0.0.3"
  29.       register: template_result
  30.  
  31.     - name: Reload Nginx if configuration changed
  32.       systemd:
  33.         name: nginx
  34.         state: reloaded
  35.       when: template_result is changed
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement