ansible-edda/playbooks/roles/services/deploy/www/tasks/main.yml

100 lines
2.9 KiB
YAML
Raw Normal View History

2022-12-18 23:43:40 +01:00
---
2022-12-16 22:16:23 +01:00
- name: "set the user variables"
ansible.builtin.import_role:
2022-12-18 19:36:21 +01:00
name: "services/include"
2022-12-16 22:16:23 +01:00
vars_from: "user"
2022-12-16 23:42:57 +01:00
- name: "set the version variables"
ansible.builtin.import_role:
2022-12-18 19:36:21 +01:00
name: "services/deploy/include"
2022-12-16 23:42:57 +01:00
vars_from: "versions"
2022-12-16 22:16:23 +01:00
- name: "check if hugo is installed"
ansible.builtin.stat:
path: "/usr/local/bin/hugo"
register: services_deploy_www_hugo_path
- block:
- name: "install hugo"
ansible.builtin.apt:
2022-12-18 23:43:40 +01:00
deb: "\
https://github.com/gohugoio/hugo/releases/download/\
v{{ services_deploy_www_hugo_version }}/\
hugo_extended_{{ services_deploy_www_hugo_version }}_Linux-64bit.deb"
2022-12-16 22:16:23 +01:00
when:
not services_deploy_www_hugo_path.stat.exists
- name: "pin hugo version"
ansible.builtin.template:
src: "./hugo/apt.j2"
dest: "/etc/apt/preferences.d/hugo"
mode: 0644
vars:
services_deploy_www_hugo_version: "0.56.0"
- block:
- name: "configure systemd service"
ansible.builtin.template:
2022-12-18 23:00:28 +01:00
src: "./systemd/{{ item }}.j2"
2022-12-16 22:16:23 +01:00
dest: "{{ services_service_user_home }}/.config/systemd/user/{{ item }}"
mode: 0600
2022-12-16 22:16:23 +01:00
loop:
- "pod-www.service"
- "container-www-nginx.service"
register: services_deploy_www_systemd_files
- name: "systemd user daemon reload"
ansible.builtin.systemd:
daemon_reload: true
scope: "user"
when:
services_deploy_www_systemd_files.changed
- name: "clone website repository"
ansible.builtin.git:
2022-12-18 23:43:40 +01:00
repo: "\
https://{{ services[services_service_name].repo_user }}:\
{{ services[services_service_name].repo_token }}@\
git.wojciechkozlowski.eu/wojtek/wojciechkozlowski.eu.git"
dest: "\
{{ services_service_user_home }}/.config/{{ services_service_user_name }}/\
wojciechkozlowski.eu"
2022-12-16 22:16:23 +01:00
recursive: true
register: services_deploy_www_webiste_git
- name: "generate static page using hugo"
ansible.builtin.command:
cmd: "hugo"
2022-12-18 23:43:40 +01:00
chdir: "\
{{ services_service_user_home }}/.config/{{ services_service_user_name }}/\
wojciechkozlowski.eu"
2022-12-16 22:16:23 +01:00
when:
services_deploy_www_webiste_git.changed
- name: "enable the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
enabled: true
scope: "user"
- name: "start the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "started"
scope: "user"
register: services_deploy_www_service_start
- name: "restart the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "restarted"
scope: "user"
2022-12-16 22:16:23 +01:00
when:
services_deploy_www_systemd_files.changed and
not services_deploy_www_service_start.changed
become_user: "{{ services_service_user_name }}"