diff --git a/lamp_ubuntu2204_onehost/playbook.yml b/lamp_ubuntu2204_onehost/playbook.yml index 9e0a33e..0a7e985 100755 --- a/lamp_ubuntu2204_onehost/playbook.yml +++ b/lamp_ubuntu2204_onehost/playbook.yml @@ -24,13 +24,18 @@ pip: name: pymysql state: present - + - name: Create document root file: path: "/var/www/{{ http_host }}" state: directory owner: "{{ app_user }}" mode: '0755' + + - name: Create document root + file: + path: "/var/www/{{ http_host }}" + dest: "/var/www/{{ http_host }}/info.php" - name: Set up Apache virtualhost template: @@ -82,6 +87,11 @@ src: "files/info.php.j2" dest: "/var/www/{{ http_host }}/info.php" + - name: Move from html/index.html to demotlc.html + command: mv /var/www/{{ http_html }}/index.html /var/www/{{ http_host }}/index.html + args: + create: /var/www/{{ http_host }}/index.html + handlers: - name: Reload Apache service: diff --git a/lamp_ubuntu2204_onehost/vars/default.yml b/lamp_ubuntu2204_onehost/vars/default.yml index 8bce145..3488cdb 100644 --- a/lamp_ubuntu2204_onehost/vars/default.yml +++ b/lamp_ubuntu2204_onehost/vars/default.yml @@ -4,4 +4,5 @@ app_user: "vagrant" http_host: "demotlc" http_conf: "demotlc.conf" http_port: "80" +http_html: "html" disable_default: true \ No newline at end of file diff --git a/objectif2/hosts b/objectif2/hosts new file mode 100644 index 0000000..29b0ea1 --- /dev/null +++ b/objectif2/hosts @@ -0,0 +1,17 @@ +[controlnode] +microk8s-controller ansible_ssh_host=192.168.56.141 +[workernode] +microk8s-node1 ansible_ssh_host=192.168.56.142 + +[all:vars] +ansible_connection=ssh +ansible_ssh_user=vagrant +ansible_ssh_user=vagrant +ansible_ssh_pass=vagrant +ansible_become_pass=vagrant +ansible_ssh_private_key_file=~/.ssh/id_ed25519 + +[controlnode:vars] +ansible_python_interpreter=/usr/bin/python3 + +[workernode:vars] diff --git a/objectif2/playbook.yml b/objectif2/playbook.yml new file mode 100755 index 0000000..d4f04d2 --- /dev/null +++ b/objectif2/playbook.yml @@ -0,0 +1,105 @@ +# https://www.reddit.com/r/ansible/comments/sn9l9d/microk8s_join_cluster_with_ansible/ +# https://canonical.com/microk8s/docs/getting-started +# https://docs.ansible.com/projects/ansible/latest/collections/kubernetes/core/docsite/kubernetes_scenarios/scenario_k8s_object.html +# https://www.reddit.com/r/kubernetes/comments/1cdfq13/microk8s_clustering_connection_filed_invalid/ +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Update prerequisites + apt: + update_cache: true + + #Install dependencies + - name: Install Snap packet + apt: + name: [ 'snap' ] + state: present + + - name: Install microk8s for All Node + become: true # needed if the other tasks are not played as root + snap: + name: microk8s + classic: yes + channel: stable + +# Control Node, create join key for worker joins +- hosts: "controlnode" + become: true + tasks: + # Create join key + - name: Create join key + # --token-ttl to avoid ERROR 500 + shell: microk8s add-node --token-ttl 300 + register: join_cluster + run_once: true + + - name: Create persistent var + set_fact: + #join: "{{ join_cluster.stdout_lines[4] | regex_replace('10\\.0\\.2\\.15', '192.168.56.141') }}" + join: "{{ join_cluster.stdout_lines[4] | regex_replace('[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+', hostvars[groups['controlnode'][0]]['ansible_ssh_host']) }}" + run_once: true + + # DEBUG: We want to see if we have the good IP or not, if not we cannot join the control + # Normally, it will use eht0 or docker bridge IP so we have to change + - name: Test var + debug: + var: join + +# Tâche 2 : Provisionnement du Worker node +# Worker Node, join from Control Node +- hosts: "workernode" + become: true + tasks: + + # Join clustor with + - name: Join cluster + # Have to use microk8s-controller here instead of a group controlnode + #shell: "{{ hostvars['microk8s-controller']['join'] }}" + # But because of it see the IP of the machine virtual, so we have to use IP of real host assigned + shell: "{{ hostvars[groups['controlnode'][0]]['join'] }} --skip-verify" + +- hosts: "controlnode" + become: true + tasks: + # Tâche 3: Déploiement d'un service dans le cluster + #Install dependencies + - name: Install Snap packet + apt: + name: [ 'python3-pip' ] + state: present + + - name: Install kubernetes + pip: + name: kubernetes + executable: pip3 + + - name: Create Nginx pod + kubernetes.core.k8s: + kubeconfig: /var/snap/microk8s/current/credentials/client.config + state: present + definition: + apiVersion: v1 + kind: Pod + metadata: + name: nginx-service + namespace: default + spec: + containers: + - name: nginx + image: nginx:stable-alpine-perl + + #Tache 3.3: Vérifiez que le pod est bien déployé. + - name: Verify nginx works + kubernetes.core.k8s_info: + kubeconfig: /var/snap/microk8s/current/credentials/client.config + kind: Pod + namespace: default + register: nginx_info + + - name: Debug pod's infomations + debug: + var: nginx_info.resources \ No newline at end of file diff --git a/vagrant/libvirt/Vagrantfile b/vagrant/libvirt/Vagrantfile index 7b3e46a..c9121ae 100644 --- a/vagrant/libvirt/Vagrantfile +++ b/vagrant/libvirt/Vagrantfile @@ -24,4 +24,4 @@ Vagrant.configure("2") do |config| slave.vm.network "private_network", ip: "192.168.56.14#{i}" end end -end \ No newline at end of file +end diff --git a/vagrant/virtualbox/Vagrantfile b/vagrant/virtualbox/Vagrantfile index 96ae97a..e67060f 100644 --- a/vagrant/virtualbox/Vagrantfile +++ b/vagrant/virtualbox/Vagrantfile @@ -24,4 +24,4 @@ Vagrant.configure("2") do |config| slave.vm.network "private_network", ip: "192.168.56.14#{i}" end end -end \ No newline at end of file +end