From d897949324350ae5ecad527be59222bdd20661f8 Mon Sep 17 00:00:00 2001 From: Siem Date: Wed, 5 Jul 2023 19:53:16 +0200 Subject: [PATCH 1/2] Add playbook for intro-cs website --- ansible/group_vars/all/websites.yml | 2 +- ansible/main.yml | 2 + ansible/roles/intro/tasks/main.yml | 104 ++++++++++++++++++ .../templates/intro-cs.conf.j2 | 2 +- ansible/roles/websites/tasks/main.yml | 2 - 5 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 ansible/roles/intro/tasks/main.yml rename ansible/roles/{websites => intro}/templates/intro-cs.conf.j2 (92%) diff --git a/ansible/group_vars/all/websites.yml b/ansible/group_vars/all/websites.yml index 80803e72b..f044a6aa4 100644 --- a/ansible/group_vars/all/websites.yml +++ b/ansible/group_vars/all/websites.yml @@ -315,7 +315,7 @@ websites: state: "present" - name: "intro-cs.{{ canonical_hostname }}" - user: "commit" + user: "intro" custom_config: true alternative_names: - "intro-cs.nl" diff --git a/ansible/main.yml b/ansible/main.yml index 3fee20398..b49bfaab2 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -64,6 +64,8 @@ tags: "radio" - role: "sodi" tags: "sodi" + - role: "intro" + tags: "intro" - role: "public_files" tags: "public" - role: "files_website" diff --git a/ansible/roles/intro/tasks/main.yml b/ansible/roles/intro/tasks/main.yml new file mode 100644 index 000000000..efc086a8e --- /dev/null +++ b/ansible/roles/intro/tasks/main.yml @@ -0,0 +1,104 @@ +--- + +- name: "create user for intro" + user: + name: "intro" + home: "/var/www/intro" + shell: "/usr/sbin/nologin" + state: "present" + system: true + +- name: "copy nginx configuration" + template: + src: "intro-cs.conf.j2" + dest: "/etc/nginx/sites-available/intro-cs.{{ canonical_hostname }}.conf" + notify: "reload nginx" + +- name: "enable nginx configuration" + file: + src: "/etc/nginx/sites-available/intro-cs.{{ canonical_hostname }}.conf" + path: "/etc/nginx/sites-enabled/intro-cs.{{ canonical_hostname }}.conf" + state: "link" + notify: "reload nginx" + +- name: "create intro webroot" + file: + path: "/var/www/intro/intro-cs.{{ canonical_hostname }}" + owner: "intro" + group: "intro" + mode: "2775" + state: "directory" +- block: + - name: "clone intro-website repository" + git: + repo: "https://github.com/svsticky/intro-website.git" + dest: "/var/www/intro/intro-cs.{{ canonical_hostname }}" + version: "intro-2023" + diff: false + register: "intro_clone" + + - name: "clone NVM" + git: + repo: "https://github.com/creationix/nvm.git" + dest: "/var/www/intro/intro-cs.{{ canonical_hostname }}/.nvm" + depth: 1 + diff: false + when: "intro_clone is changed" + + - name: "install node version" + shell: | + . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + nvm install + args: + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + executable: "/bin/bash" + when: "intro_clone is changed" + register: "install_node_version" + + - name: "run npm rebuild if needed" + shell: | + . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + npm rebuild + args: + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + executable: "/bin/bash" + when: "install_node_version is changed" + + - name: "run npm install" + shell: | + . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + npm install + args: + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + executable: "/bin/bash" + when: "intro_clone is changed" + + - name: "try building website" + block: + - name: "build website" + shell: | + . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + npm run build + args: + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + executable: "/bin/bash" + when: "intro_clone is changed" + + - name: "copy website contents to webroot" + synchronize: + src: "/var/www/intro/intro-cs.{{ canonical_hostname}}/public/" + dest: "/var/www/intro/intro-cs.{{ canonical_hostname}}/" + delete: true + recursive: true + perms: false + times: false + delegate_to: "{{ inventory_hostname }}" + + - name: "set permissions group on intro-cs files" + file: + path: "/var/www/intro/intro-cs.{{ canonical_hostname }}" + owner: "intro" + group: "intro" + recurse: true + state: "directory" + become_user: "intro" \ No newline at end of file diff --git a/ansible/roles/websites/templates/intro-cs.conf.j2 b/ansible/roles/intro/templates/intro-cs.conf.j2 similarity index 92% rename from ansible/roles/websites/templates/intro-cs.conf.j2 rename to ansible/roles/intro/templates/intro-cs.conf.j2 index 1bcc2f1d9..50c05ccda 100644 --- a/ansible/roles/websites/templates/intro-cs.conf.j2 +++ b/ansible/roles/intro/templates/intro-cs.conf.j2 @@ -13,7 +13,7 @@ server { ssl_certificate_key /etc/letsencrypt/live/intro-cs.{{ canonical_hostname }}/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/intro-cs.{{ canonical_hostname }}/chain.pem; - root /var/www/commit/intro-cs.{{ canonical_hostname }}; + root /var/www/intro/intro-cs.{{ canonical_hostname }}; index index.html index.htm; diff --git a/ansible/roles/websites/tasks/main.yml b/ansible/roles/websites/tasks/main.yml index c84240637..f35829db0 100644 --- a/ansible/roles/websites/tasks/main.yml +++ b/ansible/roles/websites/tasks/main.yml @@ -57,8 +57,6 @@ dest: "savadaba.{{ canonical_hostname }}" - src: "wintersport" dest: "wintersport.{{ canonical_hostname }}" - - src: "intro-cs" - dest: "intro-cs.{{ canonical_hostname }}" notify: "reload nginx" loop_control: label: "{{ item.dest }}" From c5d76d2345eeaca29b1963fd46a08bb69db3ce9d Mon Sep 17 00:00:00 2001 From: Siem Date: Wed, 5 Jul 2023 19:57:21 +0200 Subject: [PATCH 2/2] Fix Lint --- ansible/roles/intro/tasks/main.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ansible/roles/intro/tasks/main.yml b/ansible/roles/intro/tasks/main.yml index efc086a8e..d0df09b31 100644 --- a/ansible/roles/intro/tasks/main.yml +++ b/ansible/roles/intro/tasks/main.yml @@ -28,7 +28,7 @@ group: "intro" mode: "2775" state: "directory" -- block: +- block: - name: "clone intro-website repository" git: repo: "https://github.com/svsticky/intro-website.git" @@ -47,29 +47,29 @@ - name: "install node version" shell: | - . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + . /var/www/intro/intro-cs.{{ canonical_hostname }}/.nvm/nvm.sh nvm install args: - chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname }}" executable: "/bin/bash" when: "intro_clone is changed" register: "install_node_version" - name: "run npm rebuild if needed" shell: | - . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + . /var/www/intro/intro-cs.{{ canonical_hostname }}/.nvm/nvm.sh npm rebuild args: - chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname }}" executable: "/bin/bash" when: "install_node_version is changed" - name: "run npm install" shell: | - . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + . /var/www/intro/intro-cs.{{ canonical_hostname }}/.nvm/nvm.sh npm install args: - chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname }}" executable: "/bin/bash" when: "intro_clone is changed" @@ -77,17 +77,17 @@ block: - name: "build website" shell: | - . /var/www/intro/intro-cs.{{ canonical_hostname}}/.nvm/nvm.sh + . /var/www/intro/intro-cs.{{ canonical_hostname }}/.nvm/nvm.sh npm run build args: - chdir: "/var/www/intro/intro-cs.{{ canonical_hostname}}" + chdir: "/var/www/intro/intro-cs.{{ canonical_hostname }}" executable: "/bin/bash" when: "intro_clone is changed" - name: "copy website contents to webroot" synchronize: - src: "/var/www/intro/intro-cs.{{ canonical_hostname}}/public/" - dest: "/var/www/intro/intro-cs.{{ canonical_hostname}}/" + src: "/var/www/intro/intro-cs.{{ canonical_hostname }}/public/" + dest: "/var/www/intro/intro-cs.{{ canonical_hostname }}/" delete: true recursive: true perms: false @@ -101,4 +101,4 @@ group: "intro" recurse: true state: "directory" - become_user: "intro" \ No newline at end of file + become_user: "intro"