diff --git a/ANSIBLE/roles/httpd/tasks/httpd_default_config.yml b/ANSIBLE/roles/httpd/tasks/httpd_default_config.yml new file mode 100644 index 0000000..55a6b65 --- /dev/null +++ b/ANSIBLE/roles/httpd/tasks/httpd_default_config.yml @@ -0,0 +1,22 @@ +--- +- name: Create index.html + ansible.builtin.template: + src: httpd/index.html.j2 + dest: "{{ httpd_site_root }}/index.html" + owner: www-data + group: www-data + mode: '0644' + +- name: Create Apache virtual host config + ansible.builtin.template: + src: httpd/vhost.conf.j2 + dest: "/etc/apache2/sites-available/{{ httpd_site_name }}.conf" + notify: Reload Apache + +- name: Enable site + ansible.builtin.command: "a2ensite {{ httpd_site_name }}" + notify: Reload Apache + +- name: Enable SSL module + ansible.builtin.command: a2enmod ssl + notify: Reload Apache diff --git a/ANSIBLE/roles/httpd/tasks/httpd_install.yml b/ANSIBLE/roles/httpd/tasks/httpd_install.yml new file mode 100644 index 0000000..9c2cddb --- /dev/null +++ b/ANSIBLE/roles/httpd/tasks/httpd_install.yml @@ -0,0 +1,22 @@ +--- +- name: Install Apache2 + ansible.builtin.apt: + name: apache2 + state: present + update_cache: true + +- name: Install Certbot and Apache plugin + ansible.builtin.apt: + name: + - certbot + - python3-certbot-apache + state: present + +- name: Ensure site root exists + ansible.builtin.file: + path: "{{ httpd_site_root }}" + state: directory + owner: www-data + group: www-data + mode: '0755' + diff --git a/ANSIBLE/roles/httpd/tasks/main.yml b/ANSIBLE/roles/httpd/tasks/main.yml index d90d4ec..ee21aa9 100644 --- a/ANSIBLE/roles/httpd/tasks/main.yml +++ b/ANSIBLE/roles/httpd/tasks/main.yml @@ -1,55 +1,18 @@ --- -- name: Install Apache2 - ansible.builtin.apt: - name: apache2 - state: present - update_cache: true -- name: Install Certbot and Apache plugin - ansible.builtin.apt: - name: - - certbot - - python3-certbot-apache - state: present - -- name: Ensure site root exists - file: - path: "{{ httpd_site_root }}" - state: directory - owner: www-data - group: www-data - mode: '0755' - -- name: Create index.html - template: - src: httpd/index.html.j2 - dest: "{{ httpd_site_root }}/index.html" - owner: www-data - group: www-data - mode: '0644' - -- name: Create Apache virtual host config - template: - src: httpd/vhost.conf.j2 - dest: "/etc/apache2/sites-available/{{ httpd_site_name }}.conf" - notify: Reload Apache - -- name: Enable site - command: "a2ensite {{ httpd_site_name }}" - notify: Reload Apache - -- name: Enable SSL module - command: a2enmod ssl - notify: Reload Apache +- name: Apache2 Install + ansible.builtin.include_tasks: httpd_install.yml +- name: Apache2 Default Config + ansible.builtin.include_tasks: httpd_default_config.yml - name: Ensure Apache is running and enabled - service: + ansible.builtin.service: name: apache2 state: started - enabled: yes + enabled: true - name: Obtain Let's Encrypt certificate using certbot - command: > + ansible.builtin.command: > certbot --apache -n --agree-tos --redirect -d {{ httpd_site_name }} --email {{ admin_email }} @@ -57,6 +20,5 @@ creates: "/etc/letsencrypt/live/{{ httpd_site_name }}/fullchain.pem" - name: PHP Application - when: httpd_php == true + when: httpd_php ansible.builtin.include_tasks: php.yml -