Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playbook for intro-cs website #435

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/group_vars/all/websites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ websites:
state: "present"

- name: "intro-cs.{{ canonical_hostname }}"
user: "commit"
user: "intro"
custom_config: true
alternative_names:
- "intro-cs.nl"
Expand Down
2 changes: 2 additions & 0 deletions ansible/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
tags: "radio"
- role: "sodi"
tags: "sodi"
- role: "intro"
tags: "intro"
- role: "public_files"
tags: "public"
- role: "files_website"
Expand Down
104 changes: 104 additions & 0 deletions ansible/roles/intro/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions ansible/roles/websites/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down