Skip to content

Commit

Permalink
Docker: Add Debian support
Browse files Browse the repository at this point in the history
  • Loading branch information
quartje committed Oct 30, 2023
1 parent 09a868f commit 6ef3830
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
8 changes: 8 additions & 0 deletions roles/docker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docker_apt_release_channel: stable
docker_repo_url: https://download.docker.com/linux
docker_apt_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
docker_apt_repository: "deb [arch={{ docker_apt_arch }} signed-by=/etc/apt/trusted.gpg.d/docker.asc] {{ docker_repo_url }}/debian {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
docker_apt_ignore_key_error: true
docker_apt_gpg_key: "{{ docker_repo_url }}/{{ ansible_distribution | lower }}/gpg"
docker_apt_gpg_key_checksum: "sha256:1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570"
docker_apt_filename: "docker"
22 changes: 11 additions & 11 deletions roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
---
- name: Add Docker GPG key.
ansible.builtin.rpm_key:
key: "https://download.docker.com/linux/centos/gpg"
state: present
- include_tasks: setup-rocky.yml
when: ansible_os_family == 'RedHat'

- name: Add Docker repository.
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: '/etc/yum.repos.d/docker-ce.repo'
owner: root
group: root
mode: "0644"
- include_tasks: setup-debian.yml
when: ansible_os_family == 'Debian'

- name: Install docker
ansible.builtin.package:
Expand Down Expand Up @@ -87,6 +80,13 @@
ansible.builtin.systemd:
service: iptables
enabled: false
when: ansible_os_family == 'RedHat'

- name: Disable the netfilter-persistent service
ansible.builtin.systemd:
service: netfilter-persistent
enabled: false
when: ansible_os_family == 'Debian'

- name: Place the new systemd service file
ansible.builtin.copy:
Expand Down
29 changes: 29 additions & 0 deletions roles/docker/tasks/setup-debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Ensure old versions of Docker are not installed.
ansible.builtin.package:
name:
- docker
- docker-engine
state: absent

- name: Ensure dependencies are installed.
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
state: present

- name: Add Docker apt key.
ansible.builtin.get_url:
url: "{{ docker_apt_gpg_key }}"
dest: /etc/apt/trusted.gpg.d/docker.asc
mode: '0644'
force: false
checksum: "{{ docker_apt_gpg_key_checksum | default(omit) }}"

- name: Add Docker repository.
ansible.builtin.apt_repository:
repo: "{{ docker_apt_repository }}"
state: present
filename: "{{ docker_apt_filename }}"
update_cache: true
12 changes: 12 additions & 0 deletions roles/docker/tasks/setup-rocky.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Add Docker GPG key.
ansible.builtin.rpm_key:
key: "https://download.docker.com/linux/centos/gpg"
state: present

- name: Add Docker repository.
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: '/etc/yum.repos.d/docker-ce.repo'
owner: root
group: root
mode: "0644"
4 changes: 4 additions & 0 deletions roles/docker/templates/ip4tables.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ done
# Add your non docker rules here

/sbin/iptables -t filter -A INPUT -p icmp -j ACCEPT
# We open port 25 on docker hosts to allow containers to send emails to the docker host itself
{% if 'docker' in group_names %}
/sbin/iptables -t filter -A INPUT -p tcp -d {{ ansible_docker0.ipv4.address }} -m multiport --dports 25 -j ACCEPT
{% endif %}

{% if iptables_incoming is defined %}
{% for service in iptables_incoming %}
Expand Down

0 comments on commit 6ef3830

Please sign in to comment.