fixed some stuff in 07 and added 10-host-vars

This commit is contained in:
Caleb Fultz 2024-07-13 23:45:31 -04:00
parent a58b8b2a16
commit e82679c9c8
16 changed files with 140 additions and 1 deletions

View File

@ -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

View File

@ -1,4 +1,3 @@
---
- name: Install apache on web servers
tags: apache
package:

5
10-host-vars/ansible.cfg Normal file
View File

@ -0,0 +1,5 @@
[defaults]
inventory = inventory
private_key_file = ~/.ssh/hetzner

View File

@ -0,0 +1,5 @@
webserver_package: httpd
webserver_service: httpd
php_package: php
database_package: mariadb
database_service: mariadb

View File

@ -0,0 +1,5 @@
webserver_package: httpd
webserver_service: httpd
php_package: php
database_package: mariadb
database_service: mariadb

View File

@ -0,0 +1,5 @@
webserver_package: apache2
webserver_service: apache2
php_package: libapache2-mod-php
database_package: mariadb-server
database_service: mariadb-server

View File

@ -0,0 +1,5 @@
webserver_package: apache2
webserver_service: apache2
php_package: libapache2-mod-php
database_package: mariadb-server
database_service: mariadb-server

8
10-host-vars/inventory Normal file
View File

@ -0,0 +1,8 @@
[web_servers]
10.0.0.7
10.0.0.8
[db_servers]
10.0.0.5
10.0.0.11

View File

@ -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

View File

@ -0,0 +1,5 @@
---
- name: install mariadb package on db servers
package:
name: "{{ database_package }}"
state: latest

View File

@ -0,0 +1,11 @@
<html>
<head>
<title>Ansible Course</title>
</head>
<body>
<p> Good evening, Caleb! </p>
</body>
</html>

View File

@ -0,0 +1,4 @@
- name: restart_apache
service:
name: "{{ webserver_package}}"
state: restarted

View File

@ -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

39
10-host-vars/site.yml Normal file
View File

@ -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