From d18fd008ac854c0654850d44516d799e861f815b Mon Sep 17 00:00:00 2001 From: Robin Opletal Date: Sun, 13 Dec 2020 17:26:19 +0100 Subject: [PATCH] Alpine support - needs a molecule test --- defaults/main.yml | 3 ++ files/grub-swapaccount.cfg | 1 + tasks/main.yml | 3 ++ tasks/setup-Alpine.yml | 65 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 files/grub-swapaccount.cfg create mode 100644 tasks/setup-Alpine.yml diff --git a/defaults/main.yml b/defaults/main.yml index fc8d79e..2b53c3a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -27,5 +27,8 @@ docker_yum_repo_enable_edge: '0' docker_yum_repo_enable_test: '0' docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg +# Used only for Alpine +configure_swapaccount: false # only works with GRUB2 automatically + # A list of users who will be added to the docker group. docker_users: [] diff --git a/files/grub-swapaccount.cfg b/files/grub-swapaccount.cfg new file mode 100644 index 0000000..a07ecad --- /dev/null +++ b/files/grub-swapaccount.cfg @@ -0,0 +1 @@ +GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} swapaccount=1" diff --git a/tasks/main.yml b/tasks/main.yml index 56449ef..6e15f8f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,6 +5,9 @@ - include_tasks: setup-Debian.yml when: ansible_os_family == 'Debian' +- include_tasks: setup-Alpine.yml + when: ansible_os_family == 'Alpine' + - name: Install Docker. package: name: "{{ docker_package }}" diff --git a/tasks/setup-Alpine.yml b/tasks/setup-Alpine.yml new file mode 100644 index 0000000..68637e7 --- /dev/null +++ b/tasks/setup-Alpine.yml @@ -0,0 +1,65 @@ +--- +- name: Update cache + apk: + update_cache: true + +- name: Make sure dependencies are present + apk: + name: "{{ item }}" + state: present + loop: + - curl + +- name: Make sure that the cgroups service is started + service: + name: cgroups + state: started + enabled: true + +- name: Set fact for the Docker package name + set_fact: + docker_package: docker + +- name: Check for the installed bootloader + shell: + cmd: grep "grub\|syslinux" /etc/apk/world | head -n1 + changed_when: false + register: bootloader + +- name: Copy the swapaccount GRUB extension file + file: + src: files/grub-swapaccount.cfg + dest: /etc/grub.d/swapaccount + when: | + configure_swapaccount and + bootloader.stdout == "grub" and + ansible_facts['cmdline'].swapaccount != 1 + register: swapaccount + +- name: Regenerate the GRUB config + shell: + cmd: 'grub-mkconfig -o /boot/grub/grub.cfg' + warn: false + when: | + configure_swapaccount and + bootloader.stdout == "grub" and + swapaccount.changed + +- debug: + msg: "The configured swappacount will be loaded after the next reboot" + when: swapaccount.changed and configure_swapaccount + +- debug: + msg: | + For memory and swap limit support, + please follow https://wiki.alpinelinux.org/wiki/Docker#Extlinux + when: bootloader.stdout == "syslinux" + +- debug: + msg: | + For memory and swap limit support, + please follow https://wiki.alpinelinux.org/wiki/Docker#Extlinux + when: bootloader.stdout == "grub" and not configure_swapaccount + +- name: Reload facts + setup: