Add glusterfs role

This commit is contained in:
Johannes Rothe 2023-09-05 23:05:22 +02:00
parent a6aa3f36ee
commit 26cb18a024
Signed by: onjen
GPG Key ID: 73F092605AF3286C
5 changed files with 102 additions and 23 deletions

30
Vagrantfile vendored
View File

@ -1,22 +1,26 @@
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/jammy64"
config.vm.define "web1" do |master|
master.vm.hostname = "web1"
master.vm.network "forwarded_port", guest: 80, host: 8080
master.vm.network "private_network", ip: "192.168.56.2"
end
config.vm.define "web2" do |master|
master.vm.hostname = "web2"
master.vm.network "forwarded_port", guest: 80, host: 8081
master.vm.network "private_network", ip: "192.168.56.3"
end
config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/playbook.yaml"
ansible.vault_password_file = "vault_pass"
N = 3
(1..N).each do |machine_id|
config.vm.define "web#{machine_id}" do |machine|
machine.vm.hostname = "web#{machine_id}"
machine.vm.network "forwarded_port", guest: 80, host: "808#{machine_id+1}"
machine.vm.network "private_network", ip: "192.168.56.#{machine_id+1}"
# Only execute once the Ansible provisioner,
# when all the machines are up and ready.
if machine_id == N
machine.vm.provision :ansible do |ansible|
# Disable default limit to connect to all the machines
ansible.limit = "all"
ansible.playbook = "ansible/playbook.yaml"
ansible.vault_password_file = "vault_pass"
end
end
end
end
end

View File

@ -11,8 +11,36 @@
db_user: wp
php:
version: 8.1
gluster:
brick_dir: /srv/data/wordpress
mount_dir: /var/www/html/wordpress
vol_name: wordpress_vol
dir_owner: wordpress
dir_group: www-data
cluster:
- 192.168.56.2
- 192.168.56.3
- 192.168.56.4
pre_tasks:
- debug: var=ansible_all_ipv4_addresses[1]
# we need gluster on all servers to configure peering
- name: Install gluster
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
name:
- glusterfs-server
become: true
- name: start service
ansible.builtin.service:
name: glusterd
state: started
enabled: true
become: true
roles:
- nginx
- mysql
- php
- glusterfs
- wordpress

View File

@ -0,0 +1,52 @@
---
- name: Create brick dir
ansible.builtin.file:
path: "{{ gluster.brick_dir }}"
state: directory
become: true
- name: Create volume
gluster.gluster.gluster_volume:
state: present
name: "{{ gluster.vol_name }}"
bricks: "{{ gluster.brick_dir }}"
cluster: "{{ gluster.cluster }}"
force: true
run_once: true
become: true
- name: Start volume
gluster.gluster.gluster_volume:
state: started
name: "{{ gluster.vol_name }}"
run_once: true
become: true
- name: Mount volume
mount:
name: "{{ gluster.mount_dir }}"
src: "{{ ansible_all_ipv4_addresses[1] }}:/{{ gluster.vol_name }}"
fstype: glusterfs
opts: "defaults,_netdev"
state: mounted
become: true
- name: Add group
ansible.builtin.group:
name: "{{ gluster.dir_owner }}"
become: true
- name: Add user
ansible.builtin.user:
name: "{{ gluster.dir_owner }}"
group: "{{ gluster.dir_group }}"
become: true
- name: Change ownership
file:
path: "{{ gluster.mount_dir }}"
owner: "{{ gluster.dir_owner }}"
group: "{{ gluster.dir_group }}"
state: directory
mode: "0755"
become: true

View File

@ -3,3 +3,5 @@
service:
name: php{{ php.version }}-fpm
state: restarted
enabled: true
become: true

View File

@ -3,12 +3,14 @@
ansible.builtin.get_url:
url: https://de.wordpress.org/latest-de_DE.tar.gz
dest: /tmp/wordpress.tar.gz
run_once: true
- name: Extract wordpress
ansible.builtin.unarchive:
src: /tmp/wordpress.tar.gz
dest: "{{ wordpress.dir | dirname }}"
remote_src: true
run_once: true
become: true
- name: Add wordpress group
@ -26,14 +28,5 @@
ansible.builtin.template:
src: "wp-config.php.j2"
dest: "{{ wordpress.dir }}/wp-config.php"
run_once: true
become: true
- name: Change ownership of wordpress installation
ansible.builtin.file:
path: "{{ wordpress.dir }}"
owner: wordpress
group: www-data
state: directory
recurse: true
become: true