From 09ce67dfcb447aaff46a507e5107c036dc5acd29 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 15 May 2019 20:17:39 +0200 Subject: o Better apt-repos. --- ansible/roles/apt-repos/defaults/main.yml | 1 + ansible/roles/apt-repos/handlers/main.yml | 3 +++ ansible/roles/apt-repos/tasks/main.yml | 5 +++++ ansible/roles/apt-repos/tasks/repo.yml | 28 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 ansible/roles/apt-repos/defaults/main.yml create mode 100644 ansible/roles/apt-repos/handlers/main.yml create mode 100644 ansible/roles/apt-repos/tasks/main.yml create mode 100644 ansible/roles/apt-repos/tasks/repo.yml (limited to 'ansible/roles/apt-repos') diff --git a/ansible/roles/apt-repos/defaults/main.yml b/ansible/roles/apt-repos/defaults/main.yml new file mode 100644 index 0000000..80975f0 --- /dev/null +++ b/ansible/roles/apt-repos/defaults/main.yml @@ -0,0 +1 @@ +apt_repos: diff --git a/ansible/roles/apt-repos/handlers/main.yml b/ansible/roles/apt-repos/handlers/main.yml new file mode 100644 index 0000000..2401293 --- /dev/null +++ b/ansible/roles/apt-repos/handlers/main.yml @@ -0,0 +1,3 @@ +- name: apt update + apt: + update_cache: true diff --git a/ansible/roles/apt-repos/tasks/main.yml b/ansible/roles/apt-repos/tasks/main.yml new file mode 100644 index 0000000..7a571d3 --- /dev/null +++ b/ansible/roles/apt-repos/tasks/main.yml @@ -0,0 +1,5 @@ +- with_dict: "{{ apt_repos|default('[]') }}" + include_tasks: repo.yml + vars: + state: "{{ item.value.state | default('present') }}" + diff --git a/ansible/roles/apt-repos/tasks/repo.yml b/ansible/roles/apt-repos/tasks/repo.yml new file mode 100644 index 0000000..135aeac --- /dev/null +++ b/ansible/roles/apt-repos/tasks/repo.yml @@ -0,0 +1,28 @@ +- name: "apt-key add {{ item.key }} (key url)" + apt_key: + id: "{{ item.value.key_id }}" + url: "{{ item.value.key_url }}" + state: "{{ state }}" + when: item.value.key_url is defined and item.value.key_id is defined + +- name: "apt-key add {{ item.key }} (keyserver)" + apt_key: + id: "{{ item.value.key_id }}" + keyserver: "{{ item.value.keyserver }}" + state: "{{ state }}" + when: item.value.keyserver is defined and item.value.key_id is defined + +- name: "add repo {{ item.key }}" + when: item.value.url is defined and state == "present" + copy: + dest: "/etc/apt/sources.list.d/{{ item.key }}.list" + content: | + deb {{ item.value.url }} {{ item.value.distro }} {{ item.value.sections }} + notify: apt update + +- name: "remove repo {{ item.key }}" + when: state == "absent" + file: + path: "/etc/apt/sources.list.d/{{ item.key }}.list" + state: absent + notify: apt update -- cgit v1.2.3