From 120f7aa01f012ab147248c611927bf962154392f Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Fri, 21 Oct 2022 17:46:00 +0200 Subject: [PATCH] =?UTF-8?q?[INFO]=20Cr=C3=A9er=20le=20d=C3=A9p=C3=B4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 68 +++++++++++++++++++++++++++++++++++++++-- defaults/main.yml | 10 ++++++ handlers/main.yml | 8 +++++ tasks/configuration.yml | 28 +++++++++++++++++ tasks/installation.yml | 32 +++++++++++++++++++ tasks/main.yml | 16 ++++++++++ vars/main.yml | 8 +++++ 7 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 tasks/configuration.yml create mode 100644 tasks/installation.yml create mode 100644 tasks/main.yml create mode 100644 vars/main.yml diff --git a/README.md b/README.md index 3edfbf7..cbdcb2d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,67 @@ -# role_modele +# role_drone_cli -Modèle \ No newline at end of file +Rôle de déploiement de l'exécutable CLI de drone.io. + +## Variables + +### drone_cli_url + +URL pointant vers l'API de github.com fournissant le lien de téléchargement de l'archive. + +Valeur par défaut: `https://api.github.com/repos/harness/drone-cli/releases/latest` + +### drone_cli_architecture + +Nécessaire pour télécharger la bonne archive depuis github.com.
+Les architectures disponibles sont visibles dans [la liste de release du dépôt](https://github.com/harness/drone-cli/releases). + +Valeur par défaut: `arm64` + +### drone_cli_server_url + +URL vers le serveur drone.io. + +Valeur par défaut: aucune + +### drone_cli_server_token + +Clef pour communiquer avec le serveur drone.io. + +Valeur par défaut: aucune + +### drone_cli_commands_args + +Liste des arguments passés à la commande `drone`. + +Valeur par défaut: aucune + +## Exemple d'utilisation + +### inventory.yml + +```yaml +--- + +all: + hosts: + host1.ykn.local: +``` + +### host_vars/host1.ykn.local.yml + +```yaml +--- + +drone_cli_architecture: "amd64" +dron +``` + +### playbook.yml + +```yaml +--- + +- hosts: 'all' + roles: + - name: drone_cli +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..04b9f03 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,10 @@ +--- +# defaults file for drone_cli + +drone_cli_architecture: "arm64" +drone_cli_url: https://api.github.com/repos/harness/drone-cli/releases/latest + +drone_cli_server_url: "" +drone_cli_server_token: "" + +drone_cli_commands_args: [] diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..cf5f3ed --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,8 @@ +--- +# handlers file for drone_cli + +- name: Installer la commande + ansible.builtin.command: + chdir: /opt + cmd: install -t /usr/local/bin drone + become: true diff --git a/tasks/configuration.yml b/tasks/configuration.yml new file mode 100644 index 0000000..79adc66 --- /dev/null +++ b/tasks/configuration.yml @@ -0,0 +1,28 @@ +--- +# tasks file for drone_cli + +- name: Récupérer les informations + ansible.builtin.command: + cmd: drone {{ item.type }} info {{ item.target }} {{ item.name }} + environment: + DRONE_SERVER: "{{ drone_cli_server_url }}" + DRONE_TOKEN: "{{ drone_cli_server_token }}" + register: info + changed_when: info.rc != 0 + diff: false + +- name: Déterminer qu'il faut mettre à jour + ansible.builtin.set_fact: + cmd_action: update + when: + - info.rc == 0 + - item.type in cmd_updatable + +- name: Exécuter les commandes + ansible.builtin.command: + cmd: drone {{ item.type }} {{ cmd_action }} {{ item.target }} {{ item.name }} {{ item.data }} + environment: + DRONE_SERVER: "{{ drone_cli_server_url }}" + DRONE_TOKEN: "{{ drone_cli_server_token }}" + changed_when: info.rc != 0 + diff: false diff --git a/tasks/installation.yml b/tasks/installation.yml new file mode 100644 index 0000000..ade5d7d --- /dev/null +++ b/tasks/installation.yml @@ -0,0 +1,32 @@ +--- +# tasks file for drone_cli + +- name: Récupérer le contenu du fichier de version + ansible.builtin.uri: + url: "{{ drone_cli_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', 'linux') | + selectattr('browser_download_url', 'search', drone_cli_architecture) | + map(attribute='browser_download_url') + }} + +- name: Extraire le runner + ansible.builtin.unarchive: + src: "{{ browser_download_url | first }}" + dest: /opt/ + remote_src: true + list_files: true + mode: u=rwX,g=rX,o=rX + become: true + notify: Installer la commande + +- name: Exécuter les handlers + ansible.builtin.meta: flush_handlers diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..39bf0b6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,16 @@ +--- +# tasks file for drone_cli + +- name: Importer les tâches d'installation + tags: installation + ansible.builtin.import_tasks: installation.yml + +- name: Inclure les tâches de configuration + tags: configuration + ansible.builtin.include_tasks: configuration.yml + when: + - drone_cli_server_url | length > 0 + - drone_cli_server_token | length > 0 + - drone_cli_commands | length > 0 + loop: "{{ drone_cli_commands }}" + run_once: true diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..20c8df1 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,8 @@ +--- +# vars file for drone_cli + +cmd_action: add +cmd_updatable: + - secret + - orgsecret + - template -- 2.39.5