diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f6f441a0156871710dcc2dba09a061c07267eb23..267a35a0fe079d92f02bc4d3e3ed5e4da4cd4e3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,3 +78,5 @@ repos: rev: v24.7.0 hooks: - id: ansible-lint + additional_dependencies: + - jmespath diff --git a/README.md b/README.md index f6b93de18fa9911e78ce01471ef55b03a20680cd..e76a8a190821673e0563a32dd9536be8a2598130 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,12 @@ The following external materials are reference during the development of this pr Explains how to use the `ansible.builtin.uri` module to access the version string of the latest Oracle VirtualBox release. * [ansible.builtin.set_fact module – Set host variable(s) and fact(s). — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/set_fact_module.html) Explains how to use the `ansible.builtin.set_fact` module to set a managed node variable. +* [Grammar — JMESPath Specification — JMESPath](https://jmespath.org/specification.html#grammar) + Explains the grammar of the `literal` and `json-value` values. +* [ends_with — Built-in Functions — JMESPath Specification — JMESPath](https://jmespath.org/specification.html#ends-with) + Explains the usage of the `ends_with` built-in function. +* [Examples – ansible.builtin.get_url module – Downloads files from HTTP, HTTPS, or FTP to node — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/get_url_module.html#examples) + Explains the usage of the ansible.builtin.get_url Ansible module. ## Licensing diff --git a/playbooks/deploy-.profile.d.yml b/playbooks/deploy-.profile.d.yml new file mode 100644 index 0000000000000000000000000000000000000000..b32967af8be1180766cd8cf938d3c60f9e58a2d7 --- /dev/null +++ b/playbooks/deploy-.profile.d.yml @@ -0,0 +1,14 @@ +# Copyright 2024 林博仁(Buo-ren Lin) +# SPDX-License-Identifier: CC-BY-SA-4.0 +- name: Deploy .profile.d to the managed nodes. + hosts: all + environment: {} + # Set these environment variables if you need to access the + # internet via an HTTP/HTTPS proxy service + #http_proxy: http://192.168.49.1:8228 + #https_proxy: http://192.168.49.1:8228 + tasks: + - name: Import corresponding task list from the brlin_os_customizations role + ansible.builtin.import_role: + name: brlin.brlin_os_customizations + tasks_from: deploy-.profile.d.yml diff --git a/tasks/deploy-.profile.d.yml b/tasks/deploy-.profile.d.yml new file mode 100644 index 0000000000000000000000000000000000000000..1ae7c7d2293f14e57ad1ac8c22200afa2cfa824d --- /dev/null +++ b/tasks/deploy-.profile.d.yml @@ -0,0 +1,65 @@ +# Task list for deploying .profile.d to the managed nodes +# +# Copyright 2024 林博仁(Buo-ren, Lin) +# SPDX-License-Identifier: CC-BY-SA-4.0 +- name: Fetch the releases information of .profile.d from GitHub. + register: _profile_d_github_releases + failed_when: >- + _profile_d_github_releases is failed + or _profile_d_github_releases.status != 200 + or _profile_d_github_releases.content | length == 0 + ansible.builtin.uri: + url: https://api.github.com/repos/brlin-tw/dot-profile.d/releases + return_content: true + headers: + Accept: application/vnd.github+json + X-GitHub-Api-Version: 2022-11-28 + +- name: Determine the latest stable release of .profile.d. + ansible.builtin.set_fact: + _profile_d_latest_release: >- + {{ + _profile_d_github_releases.json + | community.general.json_query('[?prerelease == `false`] | [0]') + }} + +- name: Determine the release archive asset of the latest stable release. + ansible.builtin.set_fact: + _profile_d_release_archive_asset: >- + {{ + _profile_d_latest_release + | community.general.json_query('assets[?ends_with(name, `"tar.gz"`)] | [0]') + }} + +- name: Determine the download URL of the .profile.d release archive. + ansible.builtin.set_fact: + _profile_d_release_archive_url: >- + {{ + _profile_d_release_archive_asset.browser_download_url + }} + _profile_d_release_archive_name: >- + {{ + _profile_d_release_archive_asset.name + }} + +- name: Ensure the cache directory exists. + ansible.builtin.file: + path: '{{ cache_dir }}' + state: directory + mode: '0755' + +- name: Determine the path of the cached .profile.d release archive. + ansible.builtin.set_fact: + _profile_d_release_archive_cached: '{{ cache_dir }}/{{ _profile_d_release_archive_name }}' + +- name: Check whether the cached .profile.d release archive exists + register: cached_release_archive_existence_raw + ansible.builtin.stat: + path: '{{ _profile_d_release_archive_cached }}' + +- name: Download release archive of .profile.d. + when: not cached_release_archive_existence_raw.stat.exists + ansible.builtin.get_url: + url: '{{ _profile_d_release_archive_url }}' + dest: '{{ _profile_d_release_archive_cached }}' + mode: '0644' diff --git a/vars/main.yml b/vars/main.yml index ca13d31d57f017990086761dd49fe6653ed1f95d..35b1fb8d8750a902e7617a1c9b4ae62512798a40 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -3,3 +3,4 @@ # Copyright 2024 林博仁(Buo-ren, Lin) # SPDX-License-Identifier: CC-BY-SA-4.0 iscan_udev_rules_file: /etc/udev/rules.d/60-iscan.rule +cache_dir: '{{ role_path }}/files/cache'