Add glusterfs role
This commit is contained in:
parent
a6aa3f36ee
commit
26cb18a024
26
Vagrantfile
vendored
26
Vagrantfile
vendored
@ -1,22 +1,26 @@
|
|||||||
VAGRANTFILE_API_VERSION = "2"
|
VAGRANTFILE_API_VERSION = "2"
|
||||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||||
config.vm.box = "ubuntu/jammy64"
|
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|
|
config.vm.provider "virtualbox" do |v|
|
||||||
v.memory = 1024
|
v.memory = 1024
|
||||||
v.cpus = 2
|
v.cpus = 2
|
||||||
end
|
end
|
||||||
config.vm.provision "ansible" do |ansible|
|
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.playbook = "ansible/playbook.yaml"
|
||||||
ansible.vault_password_file = "vault_pass"
|
ansible.vault_password_file = "vault_pass"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,8 +11,36 @@
|
|||||||
db_user: wp
|
db_user: wp
|
||||||
php:
|
php:
|
||||||
version: 8.1
|
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:
|
roles:
|
||||||
- nginx
|
- nginx
|
||||||
- mysql
|
- mysql
|
||||||
- php
|
- php
|
||||||
|
- glusterfs
|
||||||
- wordpress
|
- wordpress
|
||||||
|
52
ansible/roles/glusterfs/tasks/main.yaml
Normal file
52
ansible/roles/glusterfs/tasks/main.yaml
Normal 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
|
@ -3,3 +3,5 @@
|
|||||||
service:
|
service:
|
||||||
name: php{{ php.version }}-fpm
|
name: php{{ php.version }}-fpm
|
||||||
state: restarted
|
state: restarted
|
||||||
|
enabled: true
|
||||||
|
become: true
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
url: https://de.wordpress.org/latest-de_DE.tar.gz
|
url: https://de.wordpress.org/latest-de_DE.tar.gz
|
||||||
dest: /tmp/wordpress.tar.gz
|
dest: /tmp/wordpress.tar.gz
|
||||||
|
run_once: true
|
||||||
|
|
||||||
- name: Extract wordpress
|
- name: Extract wordpress
|
||||||
ansible.builtin.unarchive:
|
ansible.builtin.unarchive:
|
||||||
src: /tmp/wordpress.tar.gz
|
src: /tmp/wordpress.tar.gz
|
||||||
dest: "{{ wordpress.dir | dirname }}"
|
dest: "{{ wordpress.dir | dirname }}"
|
||||||
remote_src: true
|
remote_src: true
|
||||||
|
run_once: true
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Add wordpress group
|
- name: Add wordpress group
|
||||||
@ -26,14 +28,5 @@
|
|||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "wp-config.php.j2"
|
src: "wp-config.php.j2"
|
||||||
dest: "{{ wordpress.dir }}/wp-config.php"
|
dest: "{{ wordpress.dir }}/wp-config.php"
|
||||||
|
run_once: true
|
||||||
become: 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
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user