diff --git a/playbooks/pimp.yml b/playbooks/pimp.yml index 50e1e71..d7a7b92 100755 --- a/playbooks/pimp.yml +++ b/playbooks/pimp.yml @@ -6,8 +6,39 @@ tasks: - name: assure mount directory file: path=/data state=directory + tags: [ pis, storage ] - name: assure mount - mount: path=/data src=LABEL=mass state=mounted + mount: path=/data src=LABEL=mass state=mounted fstype=ext4 + tags: [ pis, storage ] + - name: assure directories in mount + file: path=/data/{{ item }} state=directory + with_items: + - nfs + - postgresql + tags: [ pis, storage ] + - name: assure symlinks to directories in mount + file: path={{ item.path }} src=/data/{{ item.src }} state=link + with_items: + - { path: /var/lib/postgresql, src: postgresql } + - { path: /srv/nfs, src: nfs } + tags: [ pis, storage ] + roles: + - role: postgresql + vars: + postgresql_hba_entries: + - { type: local, database: all, user: postgres, auth_method: peer } + - { type: local, database: all, user: all, auth_method: md5 } + - { type: host, database: all, user: all, address: '127.0.0.0/8', auth_method: md5 } + - { type: host, database: all, user: all, address: '::1/128', auth_method: md5 } + # Used for internal access from other nodes + - { type: host, database: all, user: all, address: '192.168.0.0/16', auth_method: md5 } + tags: [ pis, storage, psql ] + - role: nfs + vars: + nfs_exports: + - "/srv/nfs/bulk 192.168.0.0/16(rw,no_root_squash,sync) 172.23.0.0/16(rw,no_root_squash,sync)" + - "/srv/nfs/k8s 192.168.103.0/24(rw,no_root_squash,sync)" + tags: [ pis, storage, nfs ] # Multipurpose Pis running unbound - hosts: pi-mp-1.desu.ltd,pi-mp-2.desu.ltd vars: diff --git a/roles/nfs/.ansible-lint b/roles/nfs/.ansible-lint new file mode 100644 index 0000000..5557294 --- /dev/null +++ b/roles/nfs/.ansible-lint @@ -0,0 +1,2 @@ +skip_list: + - '106' diff --git a/roles/nfs/.github/FUNDING.yml b/roles/nfs/.github/FUNDING.yml new file mode 100644 index 0000000..96b4938 --- /dev/null +++ b/roles/nfs/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms +--- +github: geerlingguy +patreon: geerlingguy diff --git a/roles/nfs/.github/stale.yml b/roles/nfs/.github/stale.yml new file mode 100644 index 0000000..c7ff127 --- /dev/null +++ b/roles/nfs/.github/stale.yml @@ -0,0 +1,56 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale +daysUntilStale: 90 + +# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. +daysUntilClose: 30 + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: + - pinned + - security + - planned + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false + +# Label to use when marking as stale +staleLabel: stale + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 + +pulls: + markComment: |- + This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale. + + unmarkComment: >- + This pull request is no longer marked for closure. + + closeComment: >- + This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details. + +issues: + markComment: |- + This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. + + unmarkComment: >- + This issue is no longer marked for closure. + + closeComment: >- + This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. diff --git a/roles/nfs/.github/workflows/ci.yml b/roles/nfs/.github/workflows/ci.yml new file mode 100644 index 0000000..8b55bd9 --- /dev/null +++ b/roles/nfs/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: "30 1 * * 3" + +defaults: + run: + working-directory: 'geerlingguy.nfs' + +jobs: + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + with: + path: 'geerlingguy.nfs' + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install yamllint ansible-lint + + - name: Lint code. + run: | + yamllint . + ansible-lint + + molecule: + name: Molecule + runs-on: ubuntu-latest + strategy: + matrix: + distro: + - centos8 + - centos7 + - ubuntu2004 + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + with: + path: 'geerlingguy.nfs' + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install ansible molecule[docker] docker + + - name: Run Molecule tests. + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/roles/nfs/.github/workflows/release.yml b/roles/nfs/.github/workflows/release.yml new file mode 100644 index 0000000..a4775fd --- /dev/null +++ b/roles/nfs/.github/workflows/release.yml @@ -0,0 +1,38 @@ +--- +# This workflow requires a GALAXY_API_KEY secret present in the GitHub +# repository or organization. +# +# See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy +# See: https://github.com/ansible/galaxy/issues/46 + +name: Release +'on': + push: + tags: + - '*' + +defaults: + run: + working-directory: 'geerlingguy.nfs' + +jobs: + + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + with: + path: 'geerlingguy.nfs' + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Ansible. + run: pip3 install ansible-base + + - name: Trigger a new import on Galaxy. + run: ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) diff --git a/roles/nfs/.gitignore b/roles/nfs/.gitignore new file mode 100644 index 0000000..f56f5b5 --- /dev/null +++ b/roles/nfs/.gitignore @@ -0,0 +1,3 @@ +*.retry +*/__pycache__ +*.pyc diff --git a/roles/nfs/.yamllint b/roles/nfs/.yamllint new file mode 100644 index 0000000..76a383c --- /dev/null +++ b/roles/nfs/.yamllint @@ -0,0 +1,10 @@ +--- +extends: default + +rules: + line-length: + max: 120 + level: warning + +ignore: | + .github/stale.yml diff --git a/roles/nfs/LICENSE b/roles/nfs/LICENSE new file mode 100644 index 0000000..4275cf3 --- /dev/null +++ b/roles/nfs/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Jeff Geerling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/roles/nfs/README.md b/roles/nfs/README.md new file mode 100644 index 0000000..97e7f04 --- /dev/null +++ b/roles/nfs/README.md @@ -0,0 +1,40 @@ +# Ansible Role: NFS + +[![CI](https://github.com/geerlingguy/ansible-role-nfs/workflows/CI/badge.svg?event=push)](https://github.com/geerlingguy/ansible-role-nfs/actions?query=workflow%3ACI) + +Installs NFS utilities on RedHat/CentOS or Debian/Ubuntu. + +## Requirements + +None. + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + nfs_exports: [] + +A list of exports which will be placed in the `/etc/exports` file. See Ubuntu's simple [Network File System (NFS)](https://ubuntu.com/server/docs/service-nfs) guide for more info and examples. (Simple example: `nfs_exports: [ "/home/public *(rw,sync,no_root_squash)" ]`). + + nfs_rpcbind_state: started + nfs_rpcbind_enabled: true + +(RedHat/CentOS/Fedora only) The state of the `rpcbind` service, and whether it should be enabled at system boot. + +## Dependencies + +None. + +## Example Playbook + + - hosts: db-servers + roles: + - { role: geerlingguy.nfs } + +## License + +MIT / BSD + +## Author Information + +This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/roles/nfs/defaults/main.yml b/roles/nfs/defaults/main.yml new file mode 100644 index 0000000..0bc919f --- /dev/null +++ b/roles/nfs/defaults/main.yml @@ -0,0 +1,5 @@ +--- +nfs_exports: [] + +nfs_rpcbind_state: started +nfs_rpcbind_enabled: true diff --git a/roles/nfs/handlers/main.yml b/roles/nfs/handlers/main.yml new file mode 100644 index 0000000..4cdcec5 --- /dev/null +++ b/roles/nfs/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: reload nfs + command: 'exportfs -ra' diff --git a/roles/nfs/meta/.galaxy_install_info b/roles/nfs/meta/.galaxy_install_info new file mode 100644 index 0000000..df99eff --- /dev/null +++ b/roles/nfs/meta/.galaxy_install_info @@ -0,0 +1,2 @@ +install_date: Mon Mar 1 02:12:55 2021 +version: 2.0.0 diff --git a/roles/nfs/meta/main.yml b/roles/nfs/meta/main.yml new file mode 100644 index 0000000..c16ec8b --- /dev/null +++ b/roles/nfs/meta/main.yml @@ -0,0 +1,30 @@ +--- +dependencies: [] + +galaxy_info: + role_name: nfs + author: geerlingguy + description: NFS installation for Linux. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 2.4 + platforms: + - name: EL + versions: + - all + - name: Fedora + versions: + - all + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + galaxy_tags: + - system + - nfs + - filesystem + - share + - nfsv4 + - efs diff --git a/roles/nfs/molecule/default/converge.yml b/roles/nfs/molecule/default/converge.yml new file mode 100644 index 0000000..ee8ce1d --- /dev/null +++ b/roles/nfs/molecule/default/converge.yml @@ -0,0 +1,13 @@ +--- +- name: Converge + hosts: all + become: true + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + changed_when: false + + roles: + - role: geerlingguy.nfs diff --git a/roles/nfs/molecule/default/molecule.yml b/roles/nfs/molecule/default/molecule.yml new file mode 100644 index 0000000..7490710 --- /dev/null +++ b/roles/nfs/molecule/default/molecule.yml @@ -0,0 +1,17 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} diff --git a/roles/nfs/tasks/main.yml b/roles/nfs/tasks/main.yml new file mode 100644 index 0000000..4100030 --- /dev/null +++ b/roles/nfs/tasks/main.yml @@ -0,0 +1,36 @@ +--- +# Include variables and define needed variables. +- name: Include OS-specific variables. + include_vars: "{{ ansible_os_family }}.yml" + +- name: Include overrides specific to Fedora. + include_vars: Fedora.yml + when: + - ansible_os_family == 'RedHat' + - ansible_distribution == "Fedora" + +# Setup/install tasks. +- include_tasks: setup-RedHat.yml + when: ansible_os_family == 'RedHat' + +- include_tasks: setup-Debian.yml + when: ansible_os_family == 'Debian' + +- name: Ensure directories to export exist + file: # noqa 208 + path: "{{ item.strip().split()[0] }}" + state: directory + with_items: "{{ nfs_exports }}" + +- name: Copy exports file. + template: + src: exports.j2 + dest: /etc/exports + owner: root + group: root + mode: 0644 + notify: reload nfs + +- name: Ensure nfs is running. + service: "name={{ nfs_server_daemon }} state=started enabled=yes" + when: nfs_exports|length diff --git a/roles/nfs/tasks/setup-Debian.yml b/roles/nfs/tasks/setup-Debian.yml new file mode 100644 index 0000000..829b614 --- /dev/null +++ b/roles/nfs/tasks/setup-Debian.yml @@ -0,0 +1,7 @@ +--- +- name: Ensure NFS utilities are installed. + apt: + name: + - nfs-common + - nfs-kernel-server + state: present diff --git a/roles/nfs/tasks/setup-RedHat.yml b/roles/nfs/tasks/setup-RedHat.yml new file mode 100644 index 0000000..d7198af --- /dev/null +++ b/roles/nfs/tasks/setup-RedHat.yml @@ -0,0 +1,9 @@ +--- +- name: Ensure NFS utilities are installed. + package: name=nfs-utils state=present + +- name: Ensure rpcbind is running as configured. + service: + name: rpcbind + state: "{{ nfs_rpcbind_state }}" + enabled: "{{ nfs_rpcbind_enabled }}" diff --git a/roles/nfs/templates/exports.j2 b/roles/nfs/templates/exports.j2 new file mode 100644 index 0000000..fa27c55 --- /dev/null +++ b/roles/nfs/templates/exports.j2 @@ -0,0 +1,13 @@ +# /etc/exports: the access control list for filesystems which may be exported +# to NFS clients. See exports(5). +# +# Example for NFSv2 and NFSv3: +# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) +# +# Example for NFSv4: +# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) +# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) +# +{% for export in nfs_exports %} +{{ export }} +{% endfor %} \ No newline at end of file diff --git a/roles/nfs/vars/Debian.yml b/roles/nfs/vars/Debian.yml new file mode 100644 index 0000000..d7ee6b5 --- /dev/null +++ b/roles/nfs/vars/Debian.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-kernel-server diff --git a/roles/nfs/vars/Fedora.yml b/roles/nfs/vars/Fedora.yml new file mode 100644 index 0000000..0538858 --- /dev/null +++ b/roles/nfs/vars/Fedora.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-server diff --git a/roles/nfs/vars/RedHat.yml b/roles/nfs/vars/RedHat.yml new file mode 100644 index 0000000..0538858 --- /dev/null +++ b/roles/nfs/vars/RedHat.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-server diff --git a/roles/requirements.yml b/roles/requirements.yml index c8a97c8..df61381 100644 --- a/roles/requirements.yml +++ b/roles/requirements.yml @@ -5,11 +5,18 @@ # MAD PROPS to geerlingguy; if for some reason you end up reading this, hit me # up and I'll buy you a beer or a pizza or something. +# DHCP # Upstream: https://github.com/bertvv/ansible-role-dhcp - src: bertvv.dhcp version: master name: dhcp +# NFS +# Upstream: https://github.com/geerlingguy/ansible-role-nfs +- src: geerlingguy.nfs + version: 2.0.0 + name: nfs + # Orchestration # Upstream: https://github.com/geerlingguy/ansible-role-docker - src: geerlingguy.docker