From a308f717a382e8bc74b887d0e9aaf82b9a621cf2 Mon Sep 17 00:00:00 2001 From: elhasnaoui <elhasnaoui@MacBook-Pro-Bilal.local> Date: Sat, 18 May 2024 17:21:49 +0200 Subject: [PATCH] Feat: Add CI pipeline to deploy the synapse application --- .gitlab-ci.yml | 36 ++++++++++++++++++++++++ .vscode/settings.json | 3 ++ group_vars/all.yml | 4 +-- inventory.ini | 8 +++--- playbooks/matrix.conf.j2 | 6 ++-- playbooks/nginx_install.yml | 26 ++++-------------- requirements.txt | 2 +- roles/nginx/README.md | 38 +++++++++++++++++++++++++ roles/nginx/defaults/main.yml | 2 ++ roles/nginx/handlers/main.yml | 2 ++ roles/nginx/meta/main.yml | 52 +++++++++++++++++++++++++++++++++++ roles/nginx/tasks/main.yml | 19 +++++++++++++ roles/nginx/tests/inventory | 2 ++ roles/nginx/tests/test.yml | 5 ++++ roles/nginx/vars/main.yml | 2 ++ 15 files changed, 176 insertions(+), 31 deletions(-) create mode 100644 .gitlab-ci.yml create mode 100644 .vscode/settings.json create mode 100644 roles/nginx/README.md create mode 100644 roles/nginx/defaults/main.yml create mode 100644 roles/nginx/handlers/main.yml create mode 100644 roles/nginx/meta/main.yml create mode 100644 roles/nginx/tasks/main.yml create mode 100644 roles/nginx/tests/inventory create mode 100644 roles/nginx/tests/test.yml create mode 100644 roles/nginx/vars/main.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ed9e9c7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,36 @@ +stages: + - build + - Config + - deploy +# TInstall the base Configuration. +Configuration_base: + stage: build + script: + - ansible-playbook -i inventory.ini main.yml --ask-vault-pass +# Upgrade packages. +Upgrade: + stage: build + script: + - ansible-playbook -i inventory.ini upgrade.yml --ask-vault-pass + +# Configure docker +Configuration_docker: + stage: Config + script: + - ansible-playbook -i inventory.ini Config.yml --ask-vault-pass +# Configure nginx +Configuration_nginx: + stage: Config + script: + - ansible-playbook -i inventory.ini nginx.yml --ask-vault-pass +# Configure postgreSQL +Configuration_postgreSQL: + stage: Config + script: + - ansible-playbook -i inventory.ini postgresql.yml --ask-vault-pass + +# Deploy the synapse app. +Configuration_Synapse: + stage: deploy + script: + - ansible-playbook -i inventory.ini synapse.yml --ask-vault-pass \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..878ec9e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ansible.python.interpreterPath": "/usr/local/bin/python3" +} \ No newline at end of file diff --git a/group_vars/all.yml b/group_vars/all.yml index ee5eebd..f8f5ce9 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -11,7 +11,5 @@ docker_apt_arch: "{{ arch }}" root_user: default_root_keys: - - name: thomas-ed25519 - key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPrw78OSJACq5MFXHrhAr2bPpnTNxwLE85mzij8gKmCs thomas@thonkpad - name: g7_key-ed25519 - key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFH+M4GLKYVf/hThCQ+DwJXYqEb7THVkfqqnVh32DAOI pifou@zabeth11 + key: <Your ed25519 public key> diff --git a/inventory.ini b/inventory.ini index 2415171..aa00ac4 100644 --- a/inventory.ini +++ b/inventory.ini @@ -1,10 +1,10 @@ [all] # Replace this with your hostname and IP address -172.26.145.114 -172.26.145.115 +<The IP address of your PostgreSQL Database VM> +<The IP address of your Synapse webserver VM> [db] -172.26.145.114 +<The IP address of your PostgreSQL Database VM> [synapse] -172.26.145.115 +<The IP address of your Synapse webserver VM> \ No newline at end of file diff --git a/playbooks/matrix.conf.j2 b/playbooks/matrix.conf.j2 index 63d1179..ccc5c73 100644 --- a/playbooks/matrix.conf.j2 +++ b/playbooks/matrix.conf.j2 @@ -1,6 +1,6 @@ server { listen 443 ssl; - server_name synapse.nyala.website; + server_name <Your synapse web server>; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA; @@ -8,8 +8,8 @@ server { ssl_session_cache shared:SSL:10m; ssl_session_tickets off; - ssl_certificate /etc/letsencrypt/live/synapse.nyala.website-0001/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/synapse.nyala.website-0001/privkey.pem; + ssl_certificate <Your Certifact SSL>; + ssl_certificate_key <Your private TLS key>; location / { proxy_pass http://127.0.0.1:8008; diff --git a/playbooks/nginx_install.yml b/playbooks/nginx_install.yml index cc2071d..8a82a02 100644 --- a/playbooks/nginx_install.yml +++ b/playbooks/nginx_install.yml @@ -1,20 +1,6 @@ -- hosts: all - tasks: - # Install nginx et assurer la dernière version. - - name: ensure nginx is at the latest version - apt: name=nginx state=latest - # Start nginx on the machine - - name: start nginx - service: - name: nginx - state: started - # Push the nginx server configuration file - - name: Upload the file of configuration to the nginx server. - copy: - src: matrix.conf.j2 - dest: /etc/nginx/sites-enabled/matrix - # Restart nginx server - - name: Restart nginx server. - service: - name: nginx - state: restarted +--- +# Cette playbook c'est pour installer la base de donner PostgreSQL sur la machine db +- name: "Install and configure nginx web server" + hosts: synapse + roles: + - nginx \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6fe9594..85c2ad2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,4 +30,4 @@ ruamel.yaml==0.18.6 ruamel.yaml.clib==0.2.8 subprocess-tee==0.4.1 wcmatch==8.5 -yamllint==1.35.1 +yamllint==1.35.1 \ No newline at end of file diff --git a/roles/nginx/README.md b/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/nginx/defaults/main.yml b/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..a28e129 --- /dev/null +++ b/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for roles/nginx diff --git a/roles/nginx/handlers/main.yml b/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..d354325 --- /dev/null +++ b/roles/nginx/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for roles/nginx diff --git a/roles/nginx/meta/main.yml b/roles/nginx/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/nginx/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..83ab03c --- /dev/null +++ b/roles/nginx/tasks/main.yml @@ -0,0 +1,19 @@ +--- +# Install nginx et assurer la dernière version. +- name: ensure nginx is at the latest version + apt: name=nginx state=latest +# Start nginx on the machine +- name: start nginx + service: + name: nginx + state: started +# Push the nginx server configuration file +- name: Upload the file of configuration to the nginx server. + copy: + src: matrix.conf.j2 + dest: /etc/nginx/sites-enabled/matrix +# Restart nginx server +- name: Restart nginx server. + service: + name: nginx + tate: restarted \ No newline at end of file diff --git a/roles/nginx/tests/inventory b/roles/nginx/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/nginx/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/nginx/tests/test.yml b/roles/nginx/tests/test.yml new file mode 100644 index 0000000..6750534 --- /dev/null +++ b/roles/nginx/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - roles/nginx diff --git a/roles/nginx/vars/main.yml b/roles/nginx/vars/main.yml new file mode 100644 index 0000000..4d5dfe2 --- /dev/null +++ b/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for roles/nginx -- GitLab