diff --git a/07-managing-services/site.yml b/07-managing-services/site.yml index eae18be..75a454f 100644 --- a/07-managing-services/site.yml +++ b/07-managing-services/site.yml @@ -48,7 +48,13 @@ owner: root group: root mode: 0644 + register: apache + - name: Restart apache + service: + name: apache2 + state: restart + when: apache.changed - hosts: db_servers tags: db, el diff --git a/09-roles/roles/base/main.yml b/09-roles/roles/base/tasks/main.yml similarity index 100% rename from 09-roles/roles/base/main.yml rename to 09-roles/roles/base/tasks/main.yml diff --git a/09-roles/roles/db_servers/main.yml b/09-roles/roles/db_servers/tasks/main.yml similarity index 100% rename from 09-roles/roles/db_servers/main.yml rename to 09-roles/roles/db_servers/tasks/main.yml diff --git a/09-roles/roles/web_servers/main.yml b/09-roles/roles/web_servers/tasks/main.yml similarity index 98% rename from 09-roles/roles/web_servers/main.yml rename to 09-roles/roles/web_servers/tasks/main.yml index 3ab3065..6ba9f53 100644 --- a/09-roles/roles/web_servers/main.yml +++ b/09-roles/roles/web_servers/tasks/main.yml @@ -1,4 +1,3 @@ ---- - name: Install apache on web servers tags: apache package: diff --git a/10-host-vars/ansible.cfg b/10-host-vars/ansible.cfg new file mode 100644 index 0000000..0056832 --- /dev/null +++ b/10-host-vars/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory = inventory +private_key_file = ~/.ssh/hetzner + + diff --git a/10-host-vars/host_vars/10.0.0.11.yml b/10-host-vars/host_vars/10.0.0.11.yml new file mode 100644 index 0000000..f17be8e --- /dev/null +++ b/10-host-vars/host_vars/10.0.0.11.yml @@ -0,0 +1,5 @@ +webserver_package: httpd +webserver_service: httpd +php_package: php +database_package: mariadb +database_service: mariadb \ No newline at end of file diff --git a/10-host-vars/host_vars/10.0.0.5.yml b/10-host-vars/host_vars/10.0.0.5.yml new file mode 100644 index 0000000..f17be8e --- /dev/null +++ b/10-host-vars/host_vars/10.0.0.5.yml @@ -0,0 +1,5 @@ +webserver_package: httpd +webserver_service: httpd +php_package: php +database_package: mariadb +database_service: mariadb \ No newline at end of file diff --git a/10-host-vars/host_vars/10.0.0.7.yml b/10-host-vars/host_vars/10.0.0.7.yml new file mode 100644 index 0000000..32ce010 --- /dev/null +++ b/10-host-vars/host_vars/10.0.0.7.yml @@ -0,0 +1,5 @@ +webserver_package: apache2 +webserver_service: apache2 +php_package: libapache2-mod-php +database_package: mariadb-server +database_service: mariadb-server \ No newline at end of file diff --git a/10-host-vars/host_vars/10.0.0.8.yml b/10-host-vars/host_vars/10.0.0.8.yml new file mode 100644 index 0000000..32ce010 --- /dev/null +++ b/10-host-vars/host_vars/10.0.0.8.yml @@ -0,0 +1,5 @@ +webserver_package: apache2 +webserver_service: apache2 +php_package: libapache2-mod-php +database_package: mariadb-server +database_service: mariadb-server \ No newline at end of file diff --git a/10-host-vars/inventory b/10-host-vars/inventory new file mode 100644 index 0000000..7b19a43 --- /dev/null +++ b/10-host-vars/inventory @@ -0,0 +1,8 @@ +[web_servers] +10.0.0.7 +10.0.0.8 + + +[db_servers] +10.0.0.5 +10.0.0.11 diff --git a/10-host-vars/roles/base/tasks/main.yml b/10-host-vars/roles/base/tasks/main.yml new file mode 100644 index 0000000..41f6511 --- /dev/null +++ b/10-host-vars/roles/base/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Install common packages + package: + name: + - htop + - neofetch + +- name: Add lfultz account + tags: lfultz + user: + name: lfultz + comment: Logan Fultz + uid: 1040 + groups: root + append: yes + shell: /bin/bash + generate_ssh_key: yes + ssh_key_bits: 2048 + ssh_key_file: .ssh/id_rsa + +- name: Add lfultz group + tags: group + group: + name: lfultz + state: present + gid: 1040 \ No newline at end of file diff --git a/10-host-vars/roles/db_servers/tasks/main.yml b/10-host-vars/roles/db_servers/tasks/main.yml new file mode 100644 index 0000000..384d2d5 --- /dev/null +++ b/10-host-vars/roles/db_servers/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- name: install mariadb package on db servers + package: + name: "{{ database_package }}" + state: latest \ No newline at end of file diff --git a/10-host-vars/roles/web_servers/files/default_site.html b/10-host-vars/roles/web_servers/files/default_site.html new file mode 100644 index 0000000..7f9c1a7 --- /dev/null +++ b/10-host-vars/roles/web_servers/files/default_site.html @@ -0,0 +1,11 @@ + + + + Ansible Course + + + +

Good evening, Caleb!

+ + + diff --git a/10-host-vars/roles/web_servers/handlers/main.yml b/10-host-vars/roles/web_servers/handlers/main.yml new file mode 100644 index 0000000..de64c4a --- /dev/null +++ b/10-host-vars/roles/web_servers/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart_apache + service: + name: "{{ webserver_package}}" + state: restarted \ No newline at end of file diff --git a/10-host-vars/roles/web_servers/tasks/main.yml b/10-host-vars/roles/web_servers/tasks/main.yml new file mode 100644 index 0000000..4c98027 --- /dev/null +++ b/10-host-vars/roles/web_servers/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: Install apache on web servers + tags: apache + package: + name: + - "{{ webserver_package }}" + - "{{ php_package }}" + +- name: Copy html file + tags: website + copy: + src: default_site.html + dest: /var/www/html/index.html + owner: root + group: root + mode: 0644 + notify: restart_apache diff --git a/10-host-vars/site.yml b/10-host-vars/site.yml new file mode 100644 index 0000000..19d28b2 --- /dev/null +++ b/10-host-vars/site.yml @@ -0,0 +1,39 @@ +--- +- hosts: all + become: true + pre_tasks: + + - name: install updates for RHEL distros + tags: always + package: + update_only: yes + update_cache: yes + when: ansible_os_family == "RedHat" + + - name: install updates for Debian distros + tags: always + package: + upgrade: dist + update_cache: yes + when: ansible_os_family == "Debian" + +- hosts: all + become: true + roles: + - base + + + +- hosts: web_servers + become: true + tags: web + roles: + - web_servers + + + +- hosts: db_servers + tags: db, + become: true + roles: + - db_servers