Skip to content

Commit 443bc1b

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

File tree

8 files changed

+64
-30
lines changed

8 files changed

+64
-30
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'

roles/apiserver_haproxy/handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
state: reloaded
66
when:
77
- apiserver_docker_compose.stat.exists != True
8-
- not(haproxy_repo_just_added is changed and ansible_check_mode)
8+
- not(_haproxy_repo_just_added is changed and ansible_check_mode)
Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
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
18+
force: true
19+
when:
20+
- haproxy_gpg_url is not none and haproxy_gpg_url|length > 0
21+
- not(_apt_keyring_directory is changed and ansible_check_mode)
22+
23+
- name: 'Add the HAProxy repository (in dry-run to check change)'
24+
apt_repository:
25+
repo: '{{ haproxy_repo_url }}'
26+
filename: haproxy
527
state: present
28+
update_cache: false
29+
check_mode: true
30+
register: _haproxy_repo_dry_run
31+
32+
- name: 'Remove repository file if modification exists.'
33+
file:
34+
dest: /etc/apt/sources.list.d/haproxy.list
35+
state: absent
36+
when: _haproxy_repo_dry_run is changed
637

738
- name: 'Add the HAProxy repository'
839
apt_repository:
9-
repo: 'deb http://haproxy.debian.net bullseye-backports-{{ _apiserver_proxy_haproxy_version | regex_replace("^(\d+[.]\d+)[.].+", "\1") }} main'
40+
repo: '{{ haproxy_repo_url }}'
1041
filename: haproxy
1142
state: present
12-
register: haproxy_repo_just_added
43+
update_cache: false
44+
register: _haproxy_repo_just_added
1345

1446
- name: 'refresh source list'
1547
apt:
1648
update_cache: true
1749
when: >-
18-
haproxy_repo_just_added is changed
50+
_haproxy_repo_just_added is changed
1951
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: 13 additions & 2 deletions
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_os_family }}.yml'
11+
- 'vars/os_{{ ansible_distribution }}.yml'
12+
- 'vars/os_{{ ansible_distribution }}_{{ ansible_distribution_release }}.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'
@@ -27,7 +38,7 @@
2738
mode: 0600
2839
notify: 'Reload HAProxy'
2940
when:
30-
- not(haproxy_repo_just_added is changed and ansible_check_mode)
41+
- not(_haproxy_repo_just_added is changed and ansible_check_mode)
3142

3243
- name: 'export vars'
3344
set_fact:

roles/apiserver_haproxy/tasks/pkg_Debian.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
- name: 'Get version of kubelet package'
2+
- name: 'Get version of haproxy package'
33
package_facts:
44

5-
- name: 'find version of kubeadm to install'
5+
- name: 'find version of haproxy to install'
66
pkg_version_match:
77
name: haproxy
88
version: '{{ _apiserver_proxy_haproxy_version }}'
99
when:
10-
- not(haproxy_repo_just_added is changed and ansible_check_mode)
10+
- not(_haproxy_repo_just_added is changed and ansible_check_mode)
1111
- packages.haproxy|default([])|select('match', _apiserver_proxy_haproxy_version)|list|length == 0
1212
register: haproxy_version
1313

@@ -28,4 +28,4 @@
2828
apt:
2929
name: 'haproxy'
3030
state: 'present'
31-
when: not(haproxy_repo_just_added is changed and ansible_check_mode)
31+
when: not(_haproxy_repo_just_added is changed and ansible_check_mode)
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=/etc/apt/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)