diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..085cfd6 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,11 @@ +--- +# +# Ansible managed +# +exclude_paths: + - ./molecule/default/prepare.yml + - ./molecule/default/converge.yml + - ./molecule/default/verify.yml + - ./molecule/default/collections.yml + - ./.tox + - ./.cache diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..f8b0654 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,30 @@ +--- +name: Bug report +about: Create a report to help me improve + +--- + +## Describe the bug + +A clear and concise description of what the bug is. + +## Playbook + +Please paste the playbook you are using. (Consider `requirements.yml` and +optionally the command you've invoked.) + + +```yaml +--- +YOUR PLAYBOOK HERE +``` + +## Output + +Show at least the error, possible related output, maybe just all the output. + +## Environment + +- Control node OS: [e.g. Debian 9] (`cat /etc/os-release`) +- Control node Ansible version: [e.g. 2.9.1] (`ansible --version`) +- Managed node OS: [e.g. CentOS 7] (`cat /etc/os-release`) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..e0512b0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +## Proposed feature + +A clear and concise description of what you want to happen. + +## Rationale + +Why is this feature required? + +## Additional context + +Add any other context about the feature request here. diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..2fb2404 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,8 @@ +--- +# +# Ansible managed +# +repository: + description: Configure mounts + homepage: https://buluma.co.ke/ + topics: mount, ansible, molecule, tox, playbook, hacktoberfest diff --git a/.github/workflows/galaxy.yml b/.github/workflows/galaxy.yml new file mode 100644 index 0000000..bfce1bf --- /dev/null +++ b/.github/workflows/galaxy.yml @@ -0,0 +1,18 @@ +--- +# +# Ansible managed +# + +name: Release to Ansible Galaxy + +on: + release: + types: [created, edited, published, released] +jobs: + release: + runs-on: ubuntu-20.04 + steps: + - name: galaxy + uses: buluma/galaxy-action@v1.0.1 + with: + galaxy_api_key: ${{ secrets.galaxy_api_key }} diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 0000000..937733d --- /dev/null +++ b/.github/workflows/molecule.yml @@ -0,0 +1,69 @@ +--- +# +# Ansible managed +# + +name: Ansible Molecule + +on: + push: + tags_ignore: + - '*' + pull_request: + schedule: + - cron: '25 13 13 * *' + +jobs: + lint: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + - name: molecule + uses: buluma/molecule-action@v4.0.5 + with: + command: lint + test: + needs: + - lint + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + config: + - image: "alpine" + tag: "latest" + - image: "debian" + tag: "latest" + - image: "debian" + tag: "bookworm" + - image: "enterpriselinux" + tag: "latest" + - image: "fedora" + tag: "34" + - image: "fedora" + tag: "latest" + - image: "fedora" + tag: "rawhide" + - image: "opensuse" + tag: "latest" + - image: "ubuntu" + tag: "latest" + - image: "ubuntu" + tag: "bionic" + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + - name: disable apparmor for mysql + run: sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ + - name: parse apparmor for mysql + run: sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld + - name: molecule + uses: buluma/molecule-action@v4.0.5 + with: + image: ${{ matrix.config.image }} + tag: ${{ matrix.config.tag }} diff --git a/.github/workflows/requirements2png.yml b/.github/workflows/requirements2png.yml new file mode 100644 index 0000000..f74ad1f --- /dev/null +++ b/.github/workflows/requirements2png.yml @@ -0,0 +1,34 @@ +--- +# +# Ansible managed +# + +on: + - push + +name: Ansible Graphviz + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: ${{ github.repository }} + - name: create png + uses: buluma/graphviz-action@1.0.0 + - name: Commit files + run: | + cd ${{ github.repository }} + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add requirements.dot requirements.png + git commit -m "Add generated files" + - name: save to png branch + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + directory: ${{ github.repository }} + force: true + branch: png diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..776527c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +--- +# +# Ansible managed +# + +name: "Test Role" + +on: + pull_request: + push: + paths: + - '.github/workflows/test.yaml' + schedule: + - cron: '1 2 * * *' + workflow_dispatch: + +jobs: + # Test the image builds and works correctly. + test: + name: Test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Test Role install. + run: ansible-galaxy install buluma.mount + + - name: Get Role ID. + run: ansible-galaxy info buluma.mount diff --git a/.github/workflows/todo.yml b/.github/workflows/todo.yml new file mode 100644 index 0000000..3e6e417 --- /dev/null +++ b/.github/workflows/todo.yml @@ -0,0 +1,20 @@ +--- +# +# Ansible managed +# + +name: "TODO 2 Issue" + +on: + push: + +jobs: + build: + runs-on: "ubuntu-20.04" + steps: + - uses: "actions/checkout@master" + - name: "TODO to Issue" + uses: "alstr/todo-to-issue-action@v2.3" + id: "todo" + with: + TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad73ff6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.molecule +*.log +*.swp +.tox +.cache +.DS_Store diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..fb3d4bd --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,24 @@ +--- +image: "buluma/github-action-molecule:4.0.5" + +services: + - docker:dind + +variables: + DOCKER_HOST: "tcp://docker:2375" + PY_COLORS: 1 + +molecule: + script: + - image=${image} tag=${tag} molecule test + rules: + - if: $CI_COMMIT_REF_NAME == "main" + retry: 1 + parallel: + matrix: + - image: "amazonlinux" + tag: "latest" + +galaxy: + script: + - ansible-galaxy role info ${CI_PROJECT_NAMESPACE}.mount diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ca0a7b8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + + - repo: https://github.com/adrienverge/yamllint + rev: v1.26.3 + hooks: + - id: yamllint + args: [-c=.yamllint] + + - repo: https://github.com/buluma/pre-commit + rev: v1.0.0 + hooks: + - id: ansible_role_find_unused_variable + - id: ansible_role_find_empty_files + - id: ansible_role_find_empty_directories + - id: ansible_role_fix_readability + - id: ansible_role_find_undefined_handlers + - id: ansible_role_find_unquoted_values diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3fcce0a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +# +# Ansible managed +# +language: python + +os: linux +dist: xenial + +python: + - "3.9" + +services: + - docker + +cache: + - pip + +install: + - pip install --upgrade pip + - pip install ansible ansible-lint yamllint + +script: + - yamllint . + - ansible-lint + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: false diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..a7ff098 --- /dev/null +++ b/.yamllint @@ -0,0 +1,16 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable + +ignore: | + .tox/ + .cache/ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..0d97a6f --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behaviour that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behaviour by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behaviour and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behaviour. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviours that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behaviour may be reported by contacting the project team at robert@meinit.nl. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..79dd235 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,74 @@ +# [Please contribute](#please-contribute) + +You can really make a difference by: + +- [Making an issue](https://help.github.com/articles/creating-an-issue/). A well described issue helps a lot. (Have a look at the [known issues](https://github.com/search?q=user%3Abuluma+is%3Aissue+state%3Aopen).) +- [Making a pull request](https://services.github.com/on-demand/github-cli/open-pull-request-github) when you see the error in code. + +I'll try to help and take every contribution seriously. + +It's a great opportunity for me to learn how you use the role and also an opportunity to get into the habit of contributing to open source software. + +## [Step by step](#step-by-step) + +Here is how you can help, a lot of steps are related to GitHub, not specifically my roles. + +### [1. Make an issue.](#1-make-an-issue) + +When you spot an issue, [create an issue](https://github.com/buluma/ansible-role-mount/issues). + +Making the issue help me and others to find similar problems in the future. + +### [2. Fork the project.](#2-fork-the-project) + +On the top right side of [the repository on GitHub](https://github.com/buluma/ansible-role-mount), click `fork`. This copies everything to your GitHub namespace. + +### [3. Make the changes](#3-make-the-changes) + +In you own GitHub namespace, make the required changes. + +I typically do that by cloning the repository (in your namespace) locally: + +``` +git clone git@github.com:YOURNAMESPACE/ansible-role-mount.git +``` + +Now you can start to edit on your laptop. + +### [4. Optionally: test your changes](#4-optionally-test-your-changes) + +Install [molecule](https://molecule.readthedocs.io/en/stable/) and [Tox](https://tox.readthedocs.io/): + +``` +pip install molecule tox ansible-lint docker +``` + +And run `molecule test`. If you want to test a specific distribution, set `image` and optionally `tag`: + +``` +image=centos tag=7 molecule test +``` + +Once it start to work, you can test multiple version of Ansible: + +``` +image=centos tag=7 tox +``` + +### [5. Optionally: Regenerate all dynamic content](#5-optionally-regenerate-all-dynamic-content) + +You can use [Ansible Generator](https://github.com/buluma/ansible-generator) to regenerate all dynamic content. + +If you don't do it, I'll do it later for you. + +### [6. Make a pull request](#6-make-a-pull-request) + +[GitHub](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork) on pull requests. + +In the comment-box, you can [refer to the issue number](https://help.github.com/en/github/writing-on-github/autolinked-references-and-urls) by using #123, where 123 is the issue number. + +### [7. Wait](#7-wait) + +Now I'll get a message that you've added some code. Thank you, really. + +CI starts to test your changes. You can follow the progress on Travis. diff --git a/LICENSE b/LICENSE index 261eeb9..33a321e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -186,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2022 Michael Buluma (me@buluma.co.ke) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 577d8e1..fcfde7a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,118 @@ -# ansible-role-mount -Configure mounts. +# [mount](#mount) + +Configure mounts + +|GitHub|GitLab|Quality|Downloads|Version| +|------|------|-------|---------|-------| +|[![github](https://github.com/buluma/ansible-role-mount/workflows/Ansible%20Molecule/badge.svg)](https://github.com/buluma/ansible-role-mount/actions)|[![gitlab](https://gitlab.com/buluma/ansible-role-mount/badges/main/pipeline.svg)](https://gitlab.com/buluma/ansible-role-mount)|[![quality](https://img.shields.io/ansible/quality/)](https://galaxy.ansible.com/buluma/mount)|[![downloads](https://img.shields.io/ansible/role/d/)](https://galaxy.ansible.com/buluma/mount)|[![Version](https://img.shields.io/github/release/buluma/ansible-role-mount.svg)](https://github.com/buluma/ansible-role-mount/releases/)| + +## [Example Playbook](#example-playbook) + +This example is taken from `molecule/default/converge.yml` and is tested on each push, pull request and release. +```yaml +--- +- name: converge + hosts: all + become: yes + gather_facts: yes + + roles: + - role: buluma.mount + mount_requests: + - path: /mnt/tmp + src: /tmp + opts: bind + fstype: none + mode: "1777" +``` + +The machine needs to be prepared. In CI this is done using `molecule/default/prepare.yml`: +```yaml +--- +- name: prepare + hosts: all + become: yes + gather_facts: no + + roles: + - role: buluma.bootstrap +``` + + +## [Role Variables](#role-variables) + +The default values for the variables are set in `defaults/main.yml`: +```yaml +--- +# defaults file for mount + +# The `mode`, `owner` and `group` can be set in the `mount_requests` list, but +# when not specified, these defaults are used. +mount_default_mode: "0750" +mount_default_owner: root +mount_default_group: root + +# You can define mounts as variables. All parameters for the `mount` module are +# supported. + +# mount_requests: +# - path: /mnt/tmp +# src: /tmp +# opts: bind +# fstype: none +# - path: swap +# src: /dev/data/swap +# fstype: swap +# opts: sw +``` + +## [Requirements](#requirements) + +- pip packages listed in [requirements.txt](https://github.com/buluma/ansible-role-mount/blob/main/requirements.txt). + +## [Status of used roles](#status-of-requirements) + +The following roles are used to prepare a system. You can prepare your system in another way. + +| Requirement | GitHub | GitLab | +|-------------|--------|--------| +|[buluma.bootstrap](https://galaxy.ansible.com/buluma/bootstrap)|[![Build Status GitHub](https://github.com/buluma/ansible-role-bootstrap/workflows/Ansible%20Molecule/badge.svg)](https://github.com/buluma/ansible-role-bootstrap/actions)|[![Build Status GitLab ](https://gitlab.com/buluma/ansible-role-bootstrap/badges/main/pipeline.svg)](https://gitlab.com/buluma/ansible-role-bootstrap)| + +## [Context](#context) + +This role is a part of many compatible roles. Have a look at [the documentation of these roles](https://buluma.co.ke/) for further information. + +Here is an overview of related roles: + +![dependencies](https://raw.githubusercontent.com/buluma/ansible-role-mount/png/requirements.png "Dependencies") + +## [Compatibility](#compatibility) + +This role has been tested on these [container images](https://hub.docker.com/u/buluma): + +|container|tags| +|---------|----| +|alpine|all| +|debian|all| +|el|8| +|fedora|all| +|opensuse|all| +|ubuntu|all| + +The minimum version of Ansible required is 2.10, tests have been done to: + +- The previous version. +- The current version. +- The development version. + + + +If you find issues, please register them in [GitHub](https://github.com/buluma/ansible-role-mount/issues) + +## [License](#license) + +Apache-2.0 + +## [Author Information](#author-information) + +[Michael Buluma](https://buluma.co.ke/) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..ea02d33 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,23 @@ +# [Security Policy](#security-policy) + +This software implements other software, it's not very likely that this software introduces new vulnerabilities. + +## [Supported Versions](#supported-versions) + +The current major version is supported. For example if the current version is 3.4.1: + +| Version | Supported | +| ------- | ------------------ | +| 3.4.1 | :white_check_mark: | +| 3.4.x | :white_check_mark: | +| 3.x.x | :white_check_mark: | +| 2.0.0 | :x: | +| 1.0.0 | :x: | + +## [Reporting a Vulnerability](#reporting-a-vulnarability) + +Please [open an issue](https://github.com/buluma/ansible-role-mount/issues) describing the vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..3010261 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,21 @@ +--- +# defaults file for mount + +# The `mode`, `owner` and `group` can be set in the `mount_requests` list, but +# when not specified, these defaults are used. +mount_default_mode: "0750" +mount_default_owner: root +mount_default_group: root + +# You can define mounts as variables. All parameters for the `mount` module are +# supported. + +# mount_requests: +# - path: /mnt/tmp +# src: /tmp +# opts: bind +# fstype: none +# - path: swap +# src: /dev/data/swap +# fstype: swap +# opts: sw diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..5ebd4e9 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- name: run swapon + ansible.builtin.command: + cmd: swapon -a + when: + - mount_requests | regex_search('(swap)') diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..66d8fee --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,33 @@ +--- +galaxy_info: + author: Michael Buluma + namespace: buluma + role_name: mount + description: Configure mounts + license: Apache-2.0 + company: none + min_ansible_version: "2.10" + + platforms: + - name: Alpine + versions: + - all + - name: Debian + versions: + - all + - name: EL + versions: + - 8 + - name: Fedora + versions: + - all + - name: OpenSUSE + versions: + - all + - name: Ubuntu + versions: + - all + galaxy_tags: + - mount + +dependencies: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..4c41c47 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,14 @@ +--- +- name: converge + hosts: all + become: yes + gather_facts: yes + + roles: + - role: ansible-role-mount + mount_requests: + - path: /mnt/tmp + src: /tmp + opts: bind + fstype: none + mode: "1777" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..2f44aed --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,27 @@ +--- +# +# Ansible managed +# +dependency: + name: galaxy + options: + role-file: requirements.yml + requirements-file: requirements.yml +lint: | + set -e + yamllint . + ansible-lint +driver: + name: docker +platforms: + - name: "mount-${image:-fedora}-${tag:-latest}${TOX_ENVNAME}" + image: "${namespace:-buluma}/${image:-fedora}:${tag:-latest}" + command: /sbin/init + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: yes + pre_build_image: yes +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..3179028 --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,8 @@ +--- +- name: prepare + hosts: all + become: yes + gather_facts: no + + roles: + - role: buluma.bootstrap diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..6b6b637 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,39 @@ +--- +- name: Verify + hosts: all + become: yes + gather_facts: no + + tasks: + - name: check directory + ansible.builtin.stat: + path: /mnt/tmp + register: mount_check_directory + failed_when: + - not mount_check_directory.stat.exists + + - name: place some file + ansible.builtin.file: + path: /mnt/tmp/some_file.txt + state: touch + mode: "0644" + + - name: unmount + ansible.posix.mount: + path: /mnt/tmp + state: unmounted + + - name: check if some file is gone + ansible.builtin.stat: + path: /mnt/tmp/some_file.txt + register: mount_check_some_file + failed_when: + - mount_check_some_file.stat.exists + + - name: revert to mounted state before verify + ansible.posix.mount: + path: /mnt/tmp + src: /tmp + opts: bind + fstype: none + state: mounted diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ba1d384 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +# These role have been tested with these PIP component. +# To install the required version yourself, use a command as: +# `python -m pip --user install -r requirements.txt` +# See the pip requirements file documentation for details: +# https://pip.pypa.io/en/stable/user_guide/#requirements-files +# +# Tests run on the previous and current (latest) version of Ansible. +ansible>=2.10 +# Some Jinja2 filters are used that are available in the newer releases. +jinja2>=2.11.2 diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..7d87107 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,5 @@ +--- +roles: + - name: buluma.bootstrap +collections: + - name: ansible.posix diff --git a/tasks/assert.yml b/tasks/assert.yml new file mode 100644 index 0000000..ff5fdbb --- /dev/null +++ b/tasks/assert.yml @@ -0,0 +1,85 @@ +--- + +- name: test if mount_default_mode is set correctly + ansible.builtin.assert: + that: + - mount_default_mode is defined + - mount_default_mode is string + quiet: yes + +- name: test if mount_default_owner is set correctly + ansible.builtin.assert: + that: + - mount_default_owner is defined + - mount_default_owner is string + quiet: yes + +- name: test if mount_default_group is set correctly + ansible.builtin.assert: + that: + - mount_default_group is defined + - mount_default_group is string + quiet: yes + +- name: test if mount_requests is set correctly + ansible.builtin.assert: + that: + - mount_requests is defined + - mount_requests is iterable + quiet: yes + +- name: test if item.backup in mount_requests is set correctly + ansible.builtin.assert: + that: + - item.backup is boolean + quiet: yes + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + when: + - item.backup is defined + +- name: test if item.boot in mount_requests is set correctly + ansible.builtin.assert: + that: + - item.boot is boolean + quiet: yes + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + when: + - item.boot is defined + +- name: test if item.fstype in mount_requests is set correctly + ansible.builtin.assert: + that: + - item.fstype is string + - item.fstype in [ "ext3", "ext4", "iso9660", "nfs", "none", "swap", "xfs" ] + quiet: yes + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + when: + - item.fstype is defined + +- name: test if item.path in mount_requests is set correctly + ansible.builtin.assert: + that: + - item.path is defined + - item.path is string + quiet: yes + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + +- name: test if item.state in mount_requests is set correctly + ansible.builtin.assert: + that: + - item.state is string + - item.state in [ "absent", "mounted", "present", "remounted", "unmounted" ] + quiet: yes + when: + - item.state is defined + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..438a273 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,41 @@ +--- +# tasks file for mount + +- name: import assert.yml + ansible.builtin.import_tasks: assert.yml + run_once: yes + delegate_to: localhost + +- name: create mountpoint + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: "{{ item.mode | default(mount_default_mode) }}" + owner: "{{ item.owner | default(mount_default_owner) }}" + group: "{{ item.group | default(mount_default_group) }}" + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + when: + - mount_requests is defined + - item.fstype != "swap" + +- name: mount requested mounts + ansible.posix.mount: + backup: "{{ item.backup | default(omit) }}" + boot: "{{ item.boot | default(omit) }}" + dump: "{{ item.dump | default(omit) }}" + fstab: "{{ item.fstab | default(omit) }}" + fstype: "{{ item.fstype | default(omit) }}" + opts: "{{ item.opts | default(omit) }}" + passno: "{{ item.passno | default(omit) }}" + path: "{{ item.path }}" + src: "{{ item.src | default(omit) }}" + state: "{{ item.state | default('mounted') }}" + loop: "{{ mount_requests }}" + loop_control: + label: "{{ item.path }}" + when: + - mount_requests is defined + notify: + - run swapon diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..88f8545 --- /dev/null +++ b/tox.ini @@ -0,0 +1,24 @@ +# +# Ansible managed +# +[tox] +minversion = 3.21.4 +envlist = py{310}-ansible-{4,5} + +skipsdist = true + +[testenv] +deps = + 4: ansible == 4.* + 5: ansible == 5.* + molecule[docker] + docker == 5.* + ansible-lint == 5.* +commands = molecule test +setenv = + TOX_ENVNAME={envname} + PY_COLORS=1 + ANSIBLE_FORCE_COLOR=1 + ANSIBLE_ROLES_PATH=../ + +passenv = namespace image tag DOCKER_HOST