Advertisement
PandaAcademy

Nginx playbook - 2

Mar 12th, 2024 (edited)
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.73 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.  
  11.     - name: Install Nginx
  12.       apt:
  13.         name: nginx
  14.         state: present
  15.  
  16.     - name: Ensure Nginx is running and enabled
  17.       systemd:
  18.         name: nginx
  19.         state: started
  20.         enabled: yes
  21.  
  22.     - name: Copy Nginx server block file
  23.       copy:
  24.         src: "templates/site.conf"
  25.         dest: "/etc/nginx/sites-enabled/site.conf"
  26.      register: template_result
  27.  
  28.     - name: Reload Nginx if configuration changed
  29.       systemd:
  30.         name: nginx
  31.         state: reloaded
  32.       when: template_result is changed
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement