Skip to content

Commit 524f133

Browse files
author
Julien Girardin
committed
Install haproxy without using apt-key. Unifies Debian and Ubuntu
1 parent fc39bcd commit 524f133

File tree

6 files changed

+63
-24
lines changed

6 files changed

+63
-24
lines changed

roles/apiserver_haproxy/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
apiserver_proxy_apiserver_port: 6443
33
_apiserver_proxy_haproxy_version: '2.6.*'
44
force_apt_update: false
5+
haproxy_repo_url: '{{ haproxy_upstream_repo_url }}'
6+
haproxy_gpg_url: '{{ haproxy_upstream_gpg_url }}'
57

68
# From apiserver_docker
79
apiserver_proxy_stack_dir: '/etc/docker-compose/apiserver-proxy'
Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,56 @@
11
---
2+
- name: 'Install software-properties-common if installing ppa'
3+
apt:
4+
name: software-properties-common
5+
when: haproxy_repo_url.startswith('ppa:')
6+
7+
- name: 'Create directory to store keys'
8+
file:
9+
dest: /etc/apt/keyrings
10+
state: directory
11+
register: _apt_keyring_directory
12+
when: haproxy_gpg_url is not none and haproxy_gpg_url|length > 0
13+
214
- name: 'Add HAProxy repo signing key'
3-
apt_key:
4-
url: 'https://haproxy.debian.net/bernat.debian.org.gpg'
15+
ansible.builtin.get_url:
16+
url: '{{ haproxy_gpg_url }}'
17+
dest: /etc/apt/keyrings/haproxy.asc'
518
state: present
19+
force: true
20+
when:
21+
- haproxy_gpg_url is not none and haproxy_gpg_url|length > 0
22+
- not(_apt_keyring_directory is changed and ansible_check_mode)
23+
24+
- name: 'Add the HAProxy repository'
25+
apt_repository:
26+
repo: '{{ haproxy_repo_url }}'
27+
filename: haproxy
28+
state: present
29+
register: _haproxy_repo_just_added
30+
31+
- name: 'Add the HAProxy repository (in dry-run to check change)'
32+
apt_repository:
33+
repo: '{{ haproxy_repo_url }}'
34+
filename: haproxy
35+
state: present
36+
register: _haproxy_repo_dry_run
37+
38+
- name: Remove repository file if modification exists.
39+
file:
40+
dest: /etc/apt/sources.list.d/haproxy.list
41+
state: absent
42+
when: _haproxy_repo_dry_run is changed
643

744
- name: 'Add the HAProxy repository'
845
apt_repository:
9-
repo: 'deb http://haproxy.debian.net bullseye-backports-{{ _apiserver_proxy_haproxy_version | regex_replace("^(\d+[.]\d+)[.].+", "\1") }} main'
46+
repo: '{{ haproxy_repo_url }}'
1047
filename: haproxy
1148
state: present
12-
register: haproxy_repo_just_added
49+
register: _haproxy_repo_just_added
1350

1451
- name: 'refresh source list'
1552
apt:
1653
update_cache: true
1754
when: >-
18-
haproxy_repo_just_added is changed
55+
_haproxy_repo_just_added is changed
1956
or force_apt_update|bool

roles/apiserver_haproxy/tasks/haproxy_repo_Ubuntu.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

roles/apiserver_haproxy/tasks/main.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
- name: 'Detect if compose-based apiserver proxy exists'
33
include_tasks: upgrade_from_docker.yml
44

5+
- name: 'Include HAproxy OS variables'
6+
include_vars: '{{ file_vars }}'
7+
loop_control:
8+
loop_var: file_vars
9+
with_fileglob:
10+
- 'vars/os_{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml'
11+
- 'vars/os_{{ ansible_distribution }}.yml'
12+
- 'vars/os_{{ ansible_os_family }}.yml'
13+
514
- name: 'Add HAProxy repository'
6-
include_tasks: '{{ item }}'
15+
include_tasks: '{{ file_tasks }}'
16+
loop_control:
17+
loop_var: file_tasks
718
with_first_found:
819
- 'haproxy_repo_{{ ansible_distribution }}_{{ ansible_distribution_release }}.yml'
920
- 'haproxy_repo_{{ ansible_distribution }}.yml'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
_haproxy_version: '{{ _apiserver_proxy_haproxy_version | regex_replace("^(\d+[.]\d+)[.].+", "\1") }}'
3+
haproxy_upstream_repo_url: 'deb [signed-by=/usr/share/keyrings/haproxy.asc] http://haproxy.debian.net {{ ansible_distribution_release }}-backports-{{ _haproxy_version }}'
4+
haproxy_upstream_gpg_url: 'https://haproxy.debian.net/bernat.debian.org.gpg'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
haproxy_upstream_repo_url: 'ppa:vbernat/haproxy-{{ _haproxy_version }}'
3+
haproxy_upstream_gpg_url:

0 commit comments

Comments
 (0)