From 003609b705ae6f6b586a4259852170405e50c7ff Mon Sep 17 00:00:00 2001 From: Brian Lee Date: Mon, 2 Sep 2024 23:11:35 -0700 Subject: [PATCH] Initialize repo. --- .gitignore | 0 LICENSE | 17 +++++++++++++++++ README.md | 31 +++++++++++++++++++++++++++++++ defaults/main.yml | 7 +++++++ meta/main.yml | 2 ++ tasks/main.yml | 26 ++++++++++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4baac1e --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +MIT No Attribution License + +Copyright (c) 2023 Brian Lee + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fe89e1 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Ansible Role: aptrepo + +Install packages from alternative apt repositories. + +Tested on: + +* Debian 12 + +## Requirements + +None. + +## Example Playbook + +```yaml +--- +- hosts: all + become: yes + gather_facts: no + roles: + - role: blee.aptrepo + tags: tor + vars: + aptrepo_key_url: https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc + aptrepo_key_filename: deb.torproject.org-keyring.gpg + aptrepo_name: torproject + aptrepo_url: https://deb.torproject.org/torproject.org + aptrepo_packages: + - tor + - deb.torproject.org-keyring +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..d5593da --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,7 @@ +--- +aptrepo_url: "" +aptrepo_key_url: "" +aptrepo_key_filename: "" +aptrepo_packages: [] +aptrepo_arch: "amd64" +aptrepo_components: "stable main" \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..6099501 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,2 @@ +--- +dependencies: [] \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..295d680 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,26 @@ +--- +# https://www.jeffgeerling.com/blog/2022/aptkey-deprecated-debianubuntu-how-fix-ansible +- name: Add repository key. + ansible.builtin.get_url: + url: "{{ aptrepo_key_url }}" + dest: "/usr/share/keyrings/{{ aptrepo_key_filename }}" + mode: '0644' + +- name: Add repository + ansible.builtin.lineinfile: + path: "/etc/apt/sources.list.d/{{ aptrepo_name }}.list" + regexp: "{{ aptrepo_key_filename }}" + line: "deb [arch={{ aptrepo_arch }} signed-by=/usr/share/keyrings/{{ aptrepo_key_filename }}] {{ aptrepo_url }} {{ aptrepo_components }}" + create: true + register: aptrepo_list + +- name: Update the apt repository cache + ansible.builtin.apt: + update_cache: yes + when: aptrepo_list.changed + +- name: Install packages + ansible.builtin.apt: + name: "{{ aptrepo_packages }}" + state: latest +