From 46fe985dd9726f8c0b6564e36d448222c367cef7 Mon Sep 17 00:00:00 2001 From: David Stephens Date: Tue, 12 Jan 2021 12:56:03 +0000 Subject: [PATCH] Move base ansible-nas configuration to roles --- group_vars/all.yml | 31 +------------------ nas.yml | 16 ++++++---- roles/ansible-nas-docker/defaults/main.yml | 12 +++++++ .../ansible-nas-docker/tasks/main.yml | 16 +++++----- .../ansible-nas-docker/templates}/daemon.json | 0 roles/ansible-nas-general/defaults/main.yml | 20 ++++++++++++ .../ansible-nas-general/files}/motd.txt | 0 .../ansible-nas-general/tasks/main.yml | 4 +-- 8 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 roles/ansible-nas-docker/defaults/main.yml rename tasks/docker.yml => roles/ansible-nas-docker/tasks/main.yml (69%) rename {templates/docker => roles/ansible-nas-docker/templates}/daemon.json (100%) create mode 100644 roles/ansible-nas-general/defaults/main.yml rename {templates/ansible-nas => roles/ansible-nas-general/files}/motd.txt (100%) rename tasks/general.yml => roles/ansible-nas-general/tasks/main.yml (94%) diff --git a/group_vars/all.yml b/group_vars/all.yml index 2cfeb12a..74064988 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -117,15 +117,7 @@ traefik_port_ui: "8083" ### ### General ### -# Sets the hostname of your Ansible NAS -ansible_nas_hostname: ansible-nas -# Sets the timezone for your Ansible NAS -# You can find a list here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones -ansible_nas_timezone: Etc/UTC - -# Update all apt packages when playbook is run -keep_packages_updated: false # Will be added to the docker group to give user command line access to docker ansible_nas_user: david @@ -136,19 +128,6 @@ ansible_nas_email: me@example.com # Applications will have subdomain SSL certificates created if Traefik is enabled, e.g. ansible-nas., nextcloud. ansible_nas_domain: example.com -### -### Docker -### -# Where you want Docker to store images -docker_image_directory: "{{ docker_home }}/data" - -# Where you want Docker to store its container data. -docker_home: /mnt/Volume2/docker - -# Docker storage driver, see https://docs.docker.com/storage/storagedriver/select-storage-driver/#supported-backing-filesystems -# You might want to change this to ZFS, depending on your underlying filesystem. -docker_storage_driver: overlay2 - ### ### Samba ### @@ -301,15 +280,7 @@ cloudflare_api_key: abcdeabcdeabcdeabcde1234512345 ### ### General ### -# Extra packages to install -ansible_nas_extra_packages: - - smartmontools - - htop - - zfsutils-linux - - bonnie++ - - unzip - - lm-sensors - - ctop + ansible_python_interpreter: /usr/bin/python3 diff --git a/nas.yml b/nas.yml index 9a783d26..e2576960 100644 --- a/nas.yml +++ b/nas.yml @@ -21,6 +21,16 @@ - docker - skip_ansible_lint + - role: ansible-nas-general + tags: + - ansible-nas-general + - ansible-nas + + - role: ansible-nas-docker + tags: + - ansible-nas-docker + - ansible-nas + - role: heimdall tags: - heimdall @@ -32,12 +42,6 @@ when: (plex_enabled | default(False)) tasks: - - import_tasks: tasks/general.yml - tags: general - - - import_tasks: tasks/docker.yml - tags: docker - - import_tasks: tasks/portainer.yml when: (portainer_enabled | default(False)) tags: portainer diff --git a/roles/ansible-nas-docker/defaults/main.yml b/roles/ansible-nas-docker/defaults/main.yml new file mode 100644 index 00000000..c0eba9ac --- /dev/null +++ b/roles/ansible-nas-docker/defaults/main.yml @@ -0,0 +1,12 @@ +--- +ansible_nas_user: david + +# Where you want Docker to store its container data. +docker_home: /mnt/Volume2/docker + +# Where you want Docker to store images +docker_image_directory: "{{ docker_home }}/data" + +# Docker storage driver, see https://docs.docker.com/storage/storagedriver/select-storage-driver/#supported-backing-filesystems +# You might want to change this to ZFS, depending on your underlying filesystem. +docker_storage_driver: overlay2 \ No newline at end of file diff --git a/tasks/docker.yml b/roles/ansible-nas-docker/tasks/main.yml similarity index 69% rename from tasks/docker.yml rename to roles/ansible-nas-docker/tasks/main.yml index f7ff349c..335574c9 100644 --- a/tasks/docker.yml +++ b/roles/ansible-nas-docker/tasks/main.yml @@ -1,44 +1,44 @@ --- -- name: install python3-pip +- name: Install python3-pip apt: name: python3-pip state: present register: result until: result is succeeded -- name: 'Remove docker-py python module' +- name: Remove docker-py python module pip: name: docker-py state: absent register: result until: result is succeeded -- name: 'Install docker python module' +- name: Install docker python module pip: name: docker state: present register: result until: result is succeeded -- name: create docker home +- name: Create Docker home directory file: path: "{{ docker_home }}" mode: 0755 state: directory -- name: add user account to docker group +- name: Add user account to Docker group user: name: "{{ ansible_nas_user }}" groups: docker append: yes -- name: update docker home from install default +- name: Update Docker home from install default template: - src: docker/daemon.json + src: daemon.json dest: /etc/docker/daemon.json register: docker_config -- name: restart docker +- name: Restart Docker service: name: docker state: restarted diff --git a/templates/docker/daemon.json b/roles/ansible-nas-docker/templates/daemon.json similarity index 100% rename from templates/docker/daemon.json rename to roles/ansible-nas-docker/templates/daemon.json diff --git a/roles/ansible-nas-general/defaults/main.yml b/roles/ansible-nas-general/defaults/main.yml new file mode 100644 index 00000000..c80d62a1 --- /dev/null +++ b/roles/ansible-nas-general/defaults/main.yml @@ -0,0 +1,20 @@ +--- +# Sets the hostname of your Ansible NAS +ansible_nas_hostname: ansible-nas + +# Update all apt packages when playbook is run +keep_packages_updated: false + +# Extra packages to install +ansible_nas_extra_packages: + - smartmontools + - htop + - zfsutils-linux + - bonnie++ + - unzip + - lm-sensors + - ctop + +# Sets the timezone for your Ansible NAS +# You can find a list here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones +ansible_nas_timezone: Etc/UTC \ No newline at end of file diff --git a/templates/ansible-nas/motd.txt b/roles/ansible-nas-general/files/motd.txt similarity index 100% rename from templates/ansible-nas/motd.txt rename to roles/ansible-nas-general/files/motd.txt diff --git a/tasks/general.yml b/roles/ansible-nas-general/tasks/main.yml similarity index 94% rename from tasks/general.yml rename to roles/ansible-nas-general/tasks/main.yml index 7ad21cef..9a882407 100644 --- a/tasks/general.yml +++ b/roles/ansible-nas-general/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: Set login banner - template: - src: ansible-nas/motd.txt + copy: + src: motd.txt dest: /etc/motd - name: Enable Universe repository