Add docker role for Linux.
This commit is contained in:
parent
43ab2d4260
commit
c596e275a9
@ -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
|
||||
|
@ -45,6 +45,7 @@
|
||||
- latex
|
||||
- pyenv
|
||||
- webcam
|
||||
- docker
|
||||
|
||||
- hosts: nat_dhcp:homeserver_nat_dhcp
|
||||
vars:
|
||||
|
15
ansible/roles/docker/tasks/common.yaml
Normal file
15
ansible/roles/docker/tasks/common.yaml
Normal 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
|
5
ansible/roles/docker/tasks/freebsd.yaml
Normal file
5
ansible/roles/docker/tasks/freebsd.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
# - name: Install packages
|
||||
# package:
|
||||
# name:
|
||||
# - foo
|
||||
# state: present
|
73
ansible/roles/docker/tasks/linux.yaml
Normal file
73
ansible/roles/docker/tasks/linux.yaml
Normal 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
|
1
ansible/roles/docker/tasks/main.yaml
Normal file
1
ansible/roles/docker/tasks/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
- import_tasks: tasks/common.yaml
|
29
ansible/roles/docker/tasks/peruser.yaml
Normal file
29
ansible/roles/docker/tasks/peruser.yaml
Normal 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"'
|
0
ansible/roles/docker/tasks/peruser_freebsd.yaml
Normal file
0
ansible/roles/docker/tasks/peruser_freebsd.yaml
Normal file
0
ansible/roles/docker/tasks/peruser_linux.yaml
Normal file
0
ansible/roles/docker/tasks/peruser_linux.yaml
Normal file
3
ansible/roles/docker/templates/daemon.json.j2
Normal file
3
ansible/roles/docker/templates/daemon.json.j2
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"storage-driver": "{{docker_storage_driver}}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user