diff --git a/README.md b/README.md index ec8b2aa..c2bebcf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vagrant -le 2023-01-17 +le 2023-01-19 Ce dépôt héberge des **Vagrantfile** dont * **docker** @@ -16,3 +16,4 @@ Ce dépôt héberge des **Vagrantfile** dont * **k8s** : kubernetes 1.26.00 + playbook pour master **k8s-master** et 2 noeuds **node-1** et **node-2** * **minione** * **rundeck** : Vagrantfile + playbook pour installation avec Mariadb + * **wp-lb** : Wordpress web1 et web2, lb HaProxy, nfs, db Mariadb - Vagrantfile + playbooks diff --git a/wp-lb/Vagrantfile b/wp-lb/Vagrantfile new file mode 100644 index 0000000..ebf699a --- /dev/null +++ b/wp-lb/Vagrantfile @@ -0,0 +1,81 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + # Base VM OS configuration. + config.vm.box = "debian/bullseye64" + config.ssh.insert_key = false + config.vm.synced_folder '.', '/vagrant', disabled: true + + # General VirtualBox VM configuration. + config.vm.provider :virtualbox do |v| + v.memory = 512 + v.cpus = 1 + v.linked_clone = true + v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + v.customize ["modifyvm", :id, "--ioapic", "on"] + end + + # lb HAproxy. + config.vm.define "lb" do |lb| + lb.vm.hostname = "lb.test" + lb.vm.network :private_network, ip: "192.168.56.2" + lb.vm.provision "shell", + inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget" + lb.vm.provision "ansible" do |ansible| + ansible.playbook = "provision/setup-lb.yml" + end + end + + # NFS. + config.vm.define "nfs" do |nfs| + nfs.vm.hostname = "nfs.test" + nfs.vm.network :private_network, ip: "192.168.56.6" + nfs.vm.provision "shell", + inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget" + nfs.vm.provision "ansible" do |ansible| + ansible.playbook = "provision/setup-nfs.yml" + end + end + + # MySQL. + config.vm.define "db" do |db| + db.vm.hostname = "db.test" + db.vm.network :private_network, ip: "192.168.56.5" + db.vm.provision "shell", + inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget" + db.vm.provision "ansible" do |ansible| + ansible.playbook = "provision/setup-db.yml" + end + end + + # Apache web1. + config.vm.define "web1" do |web1| + web1.vm.hostname = "web1.test" + web1.vm.network :private_network, ip: "192.168.56.3" + web1.vm.provider :virtualbox do |v| + v.customize ["modifyvm", :id, "--memory", 512] + end + web1.vm.provision "shell", + inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget" + web1.vm.provision "ansible" do |ansible| + ansible.playbook = "provision/setup-web.yml" + end + end + + # Apachei web2. + config.vm.define "web2" do |web2| + web2.vm.hostname = "web2.test" + web2.vm.network :private_network, ip: "192.168.56.4" + web2.vm.provider :virtualbox do |v| + v.customize ["modifyvm", :id, "--memory", 512] + end + web2.vm.provision "shell", + inline: "sudo apt-get update ; sudo apt-get install -y vim curl wget" + web2.vm.provision "ansible" do |ansible| + ansible.playbook = "provision/setup-web.yml" + end + end + +end + diff --git a/wp-lb/provision/setup-db.yml b/wp-lb/provision/setup-db.yml new file mode 100644 index 0000000..1863ded --- /dev/null +++ b/wp-lb/provision/setup-db.yml @@ -0,0 +1,43 @@ +--- +- hosts: all + become: true + tasks: + - name: modules python pour + apt: + name: python3-pymysql + state: present + + - name: install mariadb-server + apt: + name: mariadb-server + state: present + + - name: Cree Bd wordpress + mysql_db: + db: wordpressdb + login_unix_socket: /var/run/mysqld/mysqld.sock + state: present + + - name: Ouvre port 3306 mariadb-server + replace: + path: /etc/mysql/mariadb.conf.d/50-server.cnf + regexp: '^bind-address.*' + replace: '#bind-adress = 127.0.0.1' + backup: yes + notify: restart mariadb + + - name: Create MySQL user for wordpress. + mysql_user: + name: wordpressuser + password: wordpresspasswd + priv: "wordpressdb.*:ALL" + host: '%' + state: present + login_unix_socket: /var/run/mysqld/mysqld.sock + + handlers: + - name: restart mariadb + ansible.builtin.service: + name: mariadb + state: restarted + diff --git a/wp-lb/provision/setup-lb.yml b/wp-lb/provision/setup-lb.yml new file mode 100644 index 0000000..8015b43 --- /dev/null +++ b/wp-lb/provision/setup-lb.yml @@ -0,0 +1,29 @@ +--- +- hosts: all + become: true + tasks: + - name: install haproxy + apt: + name: haproxy + state: present + + - name: parametre backend et fontend + blockinfile: + path: /etc/haproxy/haproxy.cfg + block: | + frontend proxypublic + bind 192.168.56.2:80 + default_backend fermeweb + + backend fermeweb + balance roundrobin + option httpclose + #option httpchk HEAD / HTTP/1.0 + server web1.test 192.168.56.3:80 check + #server web2.test 192.168.56.4:80 check + + - name: redemarre haproxy + service: + name: haproxy + state: restarted + enabled: yes diff --git a/wp-lb/provision/setup-nfs.yml b/wp-lb/provision/setup-nfs.yml new file mode 100644 index 0000000..532c6d4 --- /dev/null +++ b/wp-lb/provision/setup-nfs.yml @@ -0,0 +1,88 @@ +--- +- hosts: all + become: true + tasks: + - name: 00 - cree repertoire wordpress pour export nfs + file: + path: /exports/wordpress + state: directory + + - name: 05 - Install nfs-server + apt: + name: nfs-server + state: present + + - name: 10 - creation fichier exports nfs + ansible.builtin.blockinfile: + path: /etc/exports + block: | + /exports/wordpress 192.168.56.0/255.255.255.0 (rw,no_root_squash,subtree_check) + + + - name: 15 - Recupere wordpress.tar.gz + get_url: + url: "https://fr.wordpress.org/latest-fr_FR.tar.gz" + dest: /tmp/wordpress-6.1.1-fr_FR.tar.gz + + - name: 20 - decompresse wordpress + unarchive: + src: /tmp/wordpress-6.1.1-fr_FR.tar.gz + dest: /exports/ + remote_src: yes + + - name: 22 - change owner et group pour repertoire wordpress + file: + path: /exports/wordpress + state: directory + recurse: yes + owner: www-data + group: www-data + + - name: 25 - genere fichier de config wordpress + copy: + src: /exports/wordpress/wp-config-sample.php + dest: /exports/wordpress/wp-config.php + remote_src: yes + + - name: 30 - genere fichier de config wordpress + copy: + src: /exports/wordpress/wp-config-sample.php + dest: /exports/wordpress/wp-config.php + remote_src: yes + + - name: 35 - ajuste variable dbname dans fichier de config wp-config.php + replace: + path: /exports/wordpress/wp-config.php + regexp: "votre_nom_de_bdd" + replace: "wordpressdb" + backup: yes + + + - name: 40 ajuste variable dbusername dans fichier de config wp-config.php + replace: + path: /exports/wordpress/wp-config.php + regexp: "votre_utilisateur_de_bdd" + replace: "wordpressuser" + backup: yes + + - name: 45 - ajuste variable mdp dans fichier de config wp-config.php + replace: + path: /exports/wordpress/wp-config.php + regexp: "votre_mdp_de_bdd" + replace: "wordpresspasswd" + backup: yes + + - name: 50 - ajuste hostname fichier wp-config.php + replace: + path: /exports/wordpress/wp-config.php + regexp: "localhost" + replace: "192.168.56.5" + backup: yes + + - name: 55 - relance nfs + service: + name: nfs-server + state: restarted + enabled: yes + + diff --git a/wp-lb/provision/setup-web.yml b/wp-lb/provision/setup-web.yml new file mode 100644 index 0000000..baca300 --- /dev/null +++ b/wp-lb/provision/setup-web.yml @@ -0,0 +1,31 @@ +--- +- hosts: all + become: true + tasks: + - name: install apache ... + apt: + name: + - apache2 + - php + - php-mbstring + - php-mysql + - mariadb-client + state: present + + - name: install nfs-common ... + apt: + name: nfs-common + state: present + + - name: montage nfs pour word press + blockinfile: + path: /etc/fstab + block: | + 192.168.56.6:/exports/wordpress /var/www/html nfs soft,timeo=5,intr,rsize=8192,wsize=8192,wsize=8192 0 0 + + - name: monte export wordpress + ansible.posix.mount: + path: /var/www/html + state: mounted + fstype: nfs + src: 192.168.56.6:/exports/wordpress