[INFO] Création du rôle (#1)

This commit is contained in:
2022-11-09 14:54:18 +00:00
parent a0a3d6f1d9
commit 74f9b1b429
9 changed files with 304 additions and 1 deletions

48
tasks/configuration.yml Normal file
View File

@@ -0,0 +1,48 @@
---
# tasks file for hugo
- name: Récupérer les informations sur le dossier des données
ansible.builtin.stat:
path: "{{ hugo_data_path }}"
become: true
register: data_path_infos
- name: Créer l'emplacement des données
ansible.builtin.file:
state: directory
path: "{{ hugo_data_path }}"
owner: root
group: root
mode: u=rw,g=r,o=
when: not data_path_infos.stat.exists
become: true
- name: Déployer le service
ansible.builtin.template:
owner: root
group: root
mode: u=rw,g=r,o=r
src: hugo.service.j2
dest: /etc/systemd/system/hugo.service
become: true
notify: Redémarrer le service
- name: Activer le service
ansible.builtin.systemd:
enabled: true
daemon_reload: true
state: restarted
name: hugo.service
when: hugo_timer_enabled
become: true
- name: Déployer la planification
ansible.builtin.template:
owner: root
group: root
mode: u=rw,g=r,o=r
src: hugo.timer.j2
dest: /etc/systemd/system/hugo.timer
when: hugo_timer_enabled
become: true
notify: Activer et exécuter la planification

49
tasks/installation.yml Normal file
View File

@@ -0,0 +1,49 @@
---
# tasks file for hugo
- name: Créer l'emplacement de stockage du binaire
ansible.builtin.file:
state: directory
path: "{{ hugo_binary_path }}"
mode: u=rwX,g=rX,o=rX
become: true
- name: Modifier l'URL pour pointer vers la version souhaitée
ansible.builtin.set_fact:
hugo_latest_url: "{{ hugo_latest_url | replace('latest', version) }}"
when: hugo_version != "latest"
vars:
version: "tags/v{{ hugo_version }}"
- name: Récupérer le contenu du fichier de version
ansible.builtin.uri:
url: "{{ hugo_latest_url }}"
return_content: true
follow_redirects: all
register: releases
- name: Extraire l'URL du paquet
ansible.builtin.set_fact:
browser_download_url: >
{{
releases.json.assets |
selectattr('browser_download_url', 'search', '.tar.gz') |
selectattr('browser_download_url', 'search', hugo_os) |
selectattr('browser_download_url', 'search', hugo_architecture) |
map(attribute='browser_download_url')
}}
- name: Extraire l'archive
ansible.builtin.unarchive:
src: "{{ browser_download_url | first }}"
dest: "{{ hugo_binary_path }}"
remote_src: true
list_files: true
mode: u=rwX,g=rX,o=rX
become: true
- name: Installer la commande
ansible.builtin.command:
cmd: install -t /usr/local/bin /opt/hugo/hugo
when: hugo_install_command
become: true

9
tasks/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
# tasks file for hugo
- name: Importer les tâches d'installation
ansible.builtin.import_tasks: installation.yml
- name: Importer les tâches de configuration
ansible.builtin.import_tasks: configuration.yml
when: hugo_install_command