Updating repo and files to look a bit more on par with the style of ansible I'm used to writing. Removing inventory as it can easily go stale and the homelab env needs to be a bit more dynamic anyway. need to find a good way to manage this but for now, no inventory is better than outdated inv.
89 lines
2.3 KiB
YAML
89 lines
2.3 KiB
YAML
---
|
|
- name: Install and setup Server for media acqusition
|
|
hosts: all
|
|
become: true
|
|
become_user: root
|
|
vars:
|
|
pip_install_packages:
|
|
- name: Docker
|
|
|
|
nfs_host: 192.168.0.109
|
|
nfs_options:
|
|
"auto,nofail,noatime,nolock,intr,tcp,actimeo=1800,x-systemd.automount"
|
|
nfs_mounts:
|
|
- remote_path: /export/Movies
|
|
local_path: /mnt/storage/movies
|
|
- remote_path: /export/TVShows
|
|
local_path: /mnt/storage/tv
|
|
- remote_path: /export/Scripts
|
|
local_path: /mnt/scripts
|
|
|
|
roles:
|
|
- geerlingguy.pip
|
|
- geerlingguy.docker
|
|
tasks:
|
|
- name: Install system packages
|
|
ansible.builtin.package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
loop:
|
|
- curl
|
|
- git
|
|
- tree
|
|
- vim
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- docker-compose
|
|
- nfs-common
|
|
|
|
- name: Mount NFS Volumes
|
|
ansible.posix.mount:
|
|
src: "{{ nfs_host }}:{{ item.remote_path }}"
|
|
path: "{{ item.local_path }}"
|
|
fstype: nfs
|
|
opts: "{{ nfs_options }}"
|
|
boot: true
|
|
state: mounted
|
|
loop: "{{ nfs_mounts | flatten }}"
|
|
|
|
- name: Update and upgrade apt packages
|
|
ansible.builtin.apt:
|
|
upgrade: true
|
|
update_cache: true
|
|
cache_valid_time: 86400
|
|
|
|
- name: Create Dockeruser and Add to Docker Group
|
|
ansible.builtin.user:
|
|
name: "{{ item.user }}"
|
|
shell: "{{ item.shell }}"
|
|
groups: "{{ item.groups }}"
|
|
loop:
|
|
- {user: "dockeruser",
|
|
shell: "/bin/bash",
|
|
groups: "docker"}
|
|
# zware user should already exist when this is run,
|
|
# most likely needs ot happen in a cloud init step
|
|
# - {user: "zware",
|
|
# shell: "/bin/zsh",
|
|
# groups: "sudo,docker"}
|
|
|
|
- name: Copy docker-compose
|
|
ansible.builtin.copy:
|
|
src: "{{ item.src }}"
|
|
dest: "{{ item.dest }}"
|
|
owner: dockeruser
|
|
group: dockeruser
|
|
mode: "{{ item.mode }}"
|
|
backup: true
|
|
loop:
|
|
- {src: "files/docker-compose.yaml",
|
|
dest: "/opt/docker-compose.yaml",
|
|
mode: "0644"}
|
|
- {src: "files/environmnet",
|
|
dest: "/opt/.env",
|
|
mode: "0600"}
|
|
|
|
- name: Start containers
|
|
community.docker.docker_compose:
|
|
project_src: /opt/
|