Add docker role for Linux.

This commit is contained in:
Tom Alexander 2023-03-25 16:08:13 -04:00
parent 43ab2d4260
commit c596e275a9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
10 changed files with 129 additions and 0 deletions

View File

@ -31,3 +31,5 @@ hwpstate: true
cores: 8
sway_conf_files:
- rofimoji
docker_storage_driver: zfs # alternatively overlay2
docker_zfs_dataset: zroot/linux/archmain/docker

View File

@ -45,6 +45,7 @@
- latex
- pyenv
- webcam
- docker
- hosts: nat_dhcp:homeserver_nat_dhcp
vars:

View File

@ -0,0 +1,15 @@
- import_tasks: tasks/freebsd.yaml
when: 'os_flavor == "freebsd"'
- import_tasks: tasks/linux.yaml
when: 'os_flavor == "linux"'
- include_tasks:
file: tasks/peruser.yaml
apply:
become: yes
become_user: "{{ initialize_user }}"
when: users is defined
loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}"
loop_control:
loop_var: initialize_user

View File

@ -0,0 +1,5 @@
# - name: Install packages
# package:
# name:
# - foo
# state: present

View File

@ -0,0 +1,73 @@
- name: Install packages
package:
name:
- docker
state: present
- name: Create docker zfs dataset
when: docker_zfs_dataset is defined and docker_zvol_size is not defined
zfs:
name: "{{ docker_zfs_dataset }}"
state: present
extra_zfs_properties:
mountpoint: /var/lib/docker
- name: Create docker zfs dataset for zvol
when: docker_zfs_dataset is defined and docker_zvol_size is defined
zfs:
name: "{{ docker_zfs_dataset }}"
state: present
- name: Create docker zvol
when: docker_zfs_dataset is defined and docker_zvol_size is defined
zfs:
name: "{{ docker_zfs_dataset }}/ext4data"
state: present
extra_zfs_properties:
volsize: "{{ docker_zvol_size }}"
- name: Create a ext4 filesystem for docker zvol
when: docker_zfs_dataset is defined and docker_zvol_size is defined
filesystem:
fstype: ext4
resizefs: true
dev: "/dev/zvol/{{ docker_zfs_dataset }}/ext4data"
- name: Mount docker zvol
when: docker_zfs_dataset is defined and docker_zvol_size is defined
mount:
path: /var/lib/docker
src: "/dev/zvol/{{ docker_zfs_dataset }}/ext4data"
fstype: ext4
state: mounted
opts: "noatime,data=writeback,barrier=0,nobh,errors=remount-ro"
- name: Create directories
when: docker_storage_driver is defined
file:
name: "{{ item }}"
state: directory
mode: 0700
owner: root
group: root
loop:
- /etc/docker
- name: Install configuration
when: docker_storage_driver is defined
template:
src: "templates/{{ item.src }}.j2"
dest: "{{ item.dest }}"
mode: 0644
owner: root
group: root
loop:
- src: daemon.json
dest: /etc/docker/daemon.json
- name: Start docker socket
systemd:
state: started
name: docker.socket
daemon_reload: yes
enabled: yes

View File

@ -0,0 +1 @@
- import_tasks: tasks/common.yaml

View File

@ -0,0 +1,29 @@
- include_role:
name: per_user
# - name: Create directories
# file:
# name: "{{ account_homedir.stdout }}/{{ item }}"
# state: directory
# mode: 0700
# owner: "{{ account_name.stdout }}"
# group: "{{ group_name.stdout }}"
# loop:
# - ".config/foo"
# - name: Copy files
# copy:
# src: "files/{{ item.src }}"
# dest: "{{ account_homedir.stdout }}/{{ item.dest }}"
# mode: 0600
# owner: "{{ account_name.stdout }}"
# group: "{{ group_name.stdout }}"
# loop:
# - src: foo.conf
# dest: .config/foo/foo.conf
- import_tasks: tasks/peruser_freebsd.yaml
when: 'os_flavor == "freebsd"'
- import_tasks: tasks/peruser_linux.yaml
when: 'os_flavor == "linux"'

View File

@ -0,0 +1,3 @@
{
"storage-driver": "{{docker_storage_driver}}"
}