Skip to content

Commit f839b1b

Browse files
authored
feat(ansible): replace "ansible.builtin.apt_key" with modern approach (#34)
1 parent 2aaad48 commit f839b1b

6 files changed

Lines changed: 45 additions & 26 deletions

File tree

whisperpine/ansitofu/roles/consul/defaults/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ consul_user: "consul"
33
consul_group: "consul"
44

55
consul_dependencies:
6-
- ca-certificates # required by the "ansible.builtin.apt_key" module
7-
- gnupg # required by the "ansible.builtin.apt_key" module
6+
- gnupg
7+
- ca-certificates # required by the "ansible.builtin.get_url" module
88
- iproute2 # make the "hostvars[inventory_hostname].ansible_default_ipv4.address" fact be gathered
99

1010
# Variables used when installing consul.
1111
consul_gpg_url: https://apt.releases.hashicorp.com/gpg
1212
consul_repo_url: https://apt.releases.hashicorp.com
13+
consul_key_file: /etc/apt/keyrings/consul.gpg
1314

1415
consul_data_dir: "/opt/consul/data"
1516
consul_config_dir: "/etc/consul.d"

whisperpine/ansitofu/roles/consul/tasks/install.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@
2222
shell: /usr/sbin/nologin
2323
system: true
2424

25-
- name: Add consul gpg key
26-
ansible.builtin.apt_key:
25+
- name: Download consul gpg key
26+
ansible.builtin.get_url:
2727
url: "{{ consul_gpg_url }}"
28-
state: present
28+
dest: /tmp/consul.asc
29+
mode: "0644"
30+
31+
- name: Convert consul gpg key to binary
32+
ansible.builtin.command:
33+
cmd: gpg --dearmor -o "{{ consul_key_file }}" /tmp/consul.asc
34+
creates: "{{ consul_key_file }}"
2935

3036
- name: Add HashiCorp apt repository
3137
ansible.builtin.apt_repository:
32-
repo: "deb [arch=amd64] {{ consul_repo_url }} {{ ansible_facts['distribution_release'] }} main"
38+
repo: >-
39+
deb [arch=amd64 signed-by={{ consul_key_file }}]
40+
{{ consul_repo_url }} {{ ansible_facts['distribution_release'] }} main
3341
state: present
3442

3543
- name: Install consul

whisperpine/ansitofu/roles/install_docker/defaults/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ install_docker_arch: amd64
44
# Repository URLs.
55
install_docker_gpg_url: https://download.docker.com/linux/ubuntu/gpg
66
install_docker_repo_url: https://download.docker.com/linux/ubuntu
7+
install_docker_key_file: /etc/apt/keyrings/docker.gpg
78

89
# Users to add to the docker group.
910
install_docker_users:
1011
- "{{ ansible_facts['user_id'] }}"
1112

1213
# Dependencies required for installation.
1314
install_docker_dependencies:
14-
- apt-transport-https
15+
- gnupg
1516
- ca-certificates
16-
- curl
17+
- apt-transport-https
1718
- software-properties-common
18-
- gnupg
19+
- curl
1920

2021
# Docker packages to install.
2122
install_docker_packages:

whisperpine/ansitofu/roles/install_docker/tasks/main.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
- name: Update apt package cache
2-
ansible.builtin.apt:
3-
update_cache: true
4-
cache_valid_time: 3600
5-
no_log: true
6-
71
- name: Install required dependencies
82
ansible.builtin.apt:
93
name: "{{ install_docker_dependencies }}"
104
state: present
5+
update_cache: true
116
no_log: true
127

13-
- name: Add Docker GPG key
14-
ansible.builtin.apt_key:
8+
- name: Download Docker GPG key
9+
ansible.builtin.get_url:
1510
url: "{{ install_docker_gpg_url }}"
16-
state: present
11+
dest: /tmp/docker.asc
12+
mode: "0644"
13+
14+
- name: Convert Docker GPG key to binary
15+
ansible.builtin.command:
16+
cmd: gpg --dearmor -o "{{ install_docker_key_file }}" /tmp/docker.asc
17+
creates: "{{ install_docker_key_file }}"
1718

1819
- name: Add Docker repository
1920
ansible.builtin.apt_repository:
20-
repo: "deb [arch={{ install_docker_arch }}] {{ install_docker_repo_url }} {{ ansible_facts['distribution_release'] }} stable"
21+
repo: >-
22+
deb [arch={{ install_docker_arch }} signed-by={{ install_docker_key_file }}]
23+
{{ install_docker_repo_url }}
24+
{{ ansible_facts['distribution_release'] }}
25+
stable
2126
state: present
2227
filename: docker
2328

whisperpine/ansitofu/roles/mongodb/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
mongodb_dependencies:
2-
- ca-certificates # required by the "ansible.builtin.apt_key" module
3-
- gnupg # required by the "ansible.builtin.apt_key" module
2+
- ca-certificates # required by the "ansible.builtin.get_url" module
43
- iproute2 # make the "hostvars[inventory_hostname].ansible_default_ipv4.address" fact be gathered
54
- cron # required by the "ansible.builtin.cron" module
65

76
mongodb_version: "8.0"
87
mongodb_repo_url: https://repo.mongodb.org/apt/ubuntu
8+
mongodb_key_file: /etc/apt/keyrings/mongodb.asc
99

1010
mongodb_port: 27017
1111
mongodb_repl_set: rs0

whisperpine/ansitofu/roles/mongodb/tasks/install.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
update_cache: true
66
no_log: true
77

8-
- name: Add mongodb gpg key
9-
ansible.builtin.apt_key:
8+
- name: Download mongodb gpg key
9+
ansible.builtin.get_url:
1010
url: https://pgp.mongodb.com/server-{{ mongodb_version }}.asc
11-
state: present
12-
no_log: true
11+
dest: "{{ mongodb_key_file }}"
12+
mode: "0644"
1313

1414
- name: Add mongodb repository
1515
ansible.builtin.apt_repository:
16-
repo: "deb [arch=amd64] {{ mongodb_repo_url }} {{ ansible_facts['distribution_release'] }}/mongodb-org/{{ mongodb_version }} multiverse"
16+
repo: >-
17+
deb [arch=amd64 signed-by={{ mongodb_key_file }}]
18+
{{ mongodb_repo_url }}
19+
{{ ansible_facts['distribution_release'] }}/mongodb-org/{{ mongodb_version }}
20+
multiverse
1721
state: present
1822

1923
- name: Install mongodb

0 commit comments

Comments
 (0)