|
| 1 | +--- |
| 2 | +# tasks file for web |
| 3 | +- name: Install required packages |
| 4 | + apt: |
| 5 | + name: |
| 6 | + - nginx |
| 7 | + - "php{{ apt_php_version }}-fpm" |
| 8 | + state: present |
| 9 | + update_cache: yes |
| 10 | + |
| 11 | +- name: Deploy nginx config |
| 12 | + template: |
| 13 | + src: nginx.conf.j2 |
| 14 | + dest: /etc/nginx/conf.d/website.conf |
| 15 | + owner: root |
| 16 | + group: root |
| 17 | + mode: 0644 |
| 18 | + notify: |
| 19 | + - restart nginx |
| 20 | + |
| 21 | +- name: ensures /var/www/html dir exists |
| 22 | + file: |
| 23 | + path: "/var/www/html" |
| 24 | + state: directory |
| 25 | + owner: www-data |
| 26 | + group: www-data |
| 27 | + mode: 0755 |
| 28 | + |
| 29 | +# setting the www.conf . |
| 30 | +- name: Set permissions on socket - owner |
| 31 | + lineinfile: |
| 32 | + dest: "/etc/php/{{ apt_php_version }}/fpm/pool.d/www.conf" |
| 33 | + regexp: '^;?listen.owner' |
| 34 | + line: "listen.owner = {{ php_owner }}" |
| 35 | + notify: restart php-fpm |
| 36 | + |
| 37 | +- name: Set permissions on socket - group |
| 38 | + lineinfile: |
| 39 | + dest: "/etc/php/{{ apt_php_version }}/fpm/pool.d/www.conf" |
| 40 | + regexp: '^;?listen.group' |
| 41 | + line: 'listen.group = {{ php_group }}' |
| 42 | + notify: restart php-fpm |
| 43 | + |
| 44 | +- name: Set permissions on socket - mode |
| 45 | + lineinfile: |
| 46 | + dest: "/etc/php/{{ apt_php_version }}/fpm/pool.d/www.conf" |
| 47 | + regexp: '^;?listen.mode' |
| 48 | + line: 'listen.mode = 0660' |
| 49 | + notify: restart php-fpm |
| 50 | + |
| 51 | +- name: Deploy index.php |
| 52 | + copy: |
| 53 | + src: index.php |
| 54 | + dest: /var/www/html/index.php |
| 55 | + owner: www-data |
| 56 | + group: www-data |
| 57 | + mode: 0644 |
| 58 | + notify: |
| 59 | + - restart php-fpm |
| 60 | + |
| 61 | +- name: Ensure php-fpm service is enabled and started |
| 62 | + service: |
| 63 | + name: php{{ apt_php_version }}-fpm |
| 64 | + state: started |
| 65 | + enabled: yes |
| 66 | + |
| 67 | +- name: Ensure nginx service is enabled and started |
| 68 | + service: |
| 69 | + name: nginx |
| 70 | + state: started |
| 71 | + enabled: yes |
| 72 | + |
| 73 | +- name: Deploy logrotate config for nginx logs |
| 74 | + copy: |
| 75 | + content: | |
| 76 | + /var/log/nginx/*log { |
| 77 | + daily |
| 78 | + missingok |
| 79 | + rotate 14 |
| 80 | + compress |
| 81 | + delaycompress |
| 82 | + notifempty |
| 83 | + create 0640 www-data adm |
| 84 | + sharedscripts |
| 85 | + postrotate |
| 86 | + [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` |
| 87 | + endscript |
| 88 | + } |
| 89 | + dest: /etc/logrotate.d/nginx |
| 90 | + owner: root |
| 91 | + group: root |
| 92 | + mode: 0644 |
| 93 | + notify: |
| 94 | + - restart nginx |
0 commit comments