add support to manage repos

This commit is contained in:
nd 2019-05-25 00:56:46 +02:00
parent 496e116830
commit 9f1729ceee
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9
4 changed files with 75 additions and 1 deletions

40
README.md Normal file
View file

@ -0,0 +1,40 @@
# Packages
## Supported
Only Apt and Debian Stretch.
Other versions might work but are not tested.
## Parameters and defaults
packages:
pkg: {}
repos: {}
All configuration is to be placed inside the `packages` dict.
```
# dictionary of package names to install. The key is the name of the packages, value musst be != none as none is used as knock out.
pkg: {}
# dictionary of repositories to setup, the key is used as name for the repository. See **repo** for definition for the content
repos: {}
```
**repo**:
```
# url to repo, example: "http://www.deb-multimedia.org stretch main non-free"
url: ''
# only set either key or keyid + keyserver
# gpg key to add for this repo
key: ''
# key id of the key to add, for example "36A1D7869245C8950F966E92D8576A8BA88D21E9"
keyid: ''
# key server to get the key from, for example "keyserver.ubuntu.com"
keyserver:
```

2
handlers/main.yml Normal file
View file

@ -0,0 +1,2 @@
- name: update apt cache
apt: update_cache=yes

View file

@ -1,11 +1,24 @@
- set_fact: - set_fact:
pkgs: "{{ packages.pkg | dict2items | rejectattr('value', 'none') | map(attribute='key') | list }}" pkgs: "{{ packages.pkg | dict2items | rejectattr('value', 'none') | map(attribute='key') | list }}"
- name: list repositories to setup
debug:
var: packages.repos
verbosity: 1
- name: list packages to install - name: list packages to install
debug: debug:
var: pkgs var: pkgs
verbosity: 1
- name: install apt-transport-https
apt: pkg=apt-transport-https
- name: setup repositories
include_tasks: repo.yml
with_items: "{{ packages.repos }}"
- meta: flush_handlers
- name: install packages - name: install packages
apt: apt:
pkg: "{{ pkgs }}" pkg: "{{ pkgs }}"
update_cache: yes

19
tasks/repo.yml Normal file
View file

@ -0,0 +1,19 @@
- set_fact:
repo: "{{ packages.repos[item] }}"
- name: "setup repo key for {{ item }}"
apt_key:
data: "{{ repo.key }}"
when: repo.key|d(false)
- name: "setup repo key for {{ item }}"
apt_key:
id: "{{ repo.keyid }}"
keyserver: "{{ repo.keyserver }}"
when:
- repo.keyid|d(false)
- repo.keyserver|d(false)
- name: "add repo {{ item }}"
apt_repository:
repo: "{{ repo.url }}"