Compare commits
66 Commits
Author | SHA1 | Date | |
---|---|---|---|
dc3ad7ac81 | |||
6cbf32519f | |||
1f33cd00c9 | |||
76d86bcf9b | |||
5df6ca3348 | |||
4c996bf5fa | |||
dc617c6b91 | |||
a3c09437f8 | |||
3b4cecedc3 | |||
e0bc8b64a8 | |||
7e00724c9a | |||
76d45b95ae | |||
6043aa8352 | |||
5705a65115 | |||
9a98e48ca6 | |||
b8263a05fa | |||
9e13515ed1 | |||
1689bca9ba | |||
f7ea140c59 | |||
ccfb90d3a4 | |||
ecacfc5da2 | |||
1f818fef32 | |||
be1cb4e1ff | |||
84d1b5eceb | |||
4870438c44 | |||
faf031258e | |||
cd4fc64f9b | |||
0db5e66a10 | |||
199f8959aa | |||
0988e79684 | |||
f0d350f552 | |||
586ba5e451 | |||
c9d74a9dda | |||
ecef66e701 | |||
e608d6877a | |||
dbf2ae95a1 | |||
9d6e54f261 | |||
c42c659bfb | |||
7aeb90c305 | |||
a765985312 | |||
93a977c4de | |||
5a21a49808 | |||
916de510eb | |||
9e28b0c45d | |||
3b51bb3976 | |||
5d3178f74e | |||
95e038107b | |||
ce0f254a56 | |||
1b71a86204 | |||
2102efe92d | |||
c66bc093ac | |||
5d53d4a17c | |||
82db81e3d6 | |||
7389e74847 | |||
249161b930 | |||
81488dc548 | |||
6dce72d18d | |||
eb4759a7d6 | |||
cac1ab20b2 | |||
7b847ef503 | |||
bc69b5d35c | |||
b4806df97a | |||
5d5f883230 | |||
3cf774f3f6 | |||
b42d0dc279 | |||
3fd2e1ba9d |
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# ---> Ansible
|
||||
*.retry
|
||||
plugins
|
||||
library
|
||||
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
7
.markdownlint.yml
Normal file
7
.markdownlint.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
default: True
|
||||
MD013: False
|
||||
MD041: False
|
||||
MD024: False
|
||||
MD004:
|
||||
style: dash
|
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
||||
LICENSE
|
47
.woodpecker/docs.yaml
Normal file
47
.woodpecker/docs.yaml
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
- name: generate
|
||||
image: quay.io/thegeeklab/ansible-doctor
|
||||
environment:
|
||||
ANSIBLE_DOCTOR_EXCLUDE_FILES: "['molecule/']"
|
||||
ANSIBLE_DOCTOR_RENDERER__FORCE_OVERWRITE: "true"
|
||||
ANSIBLE_DOCTOR_LOGGING__LEVEL: info
|
||||
ANSIBLE_DOCTOR_ROLE__NAME: ${CI_REPO_NAME}
|
||||
ANSIBLE_DOCTOR_TEMPLATE__NAME: readme
|
||||
|
||||
- name: format
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- prettier -w README.md
|
||||
|
||||
- name: diff
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- git diff --color=always README.md
|
||||
|
||||
- name: publish
|
||||
image: quay.io/thegeeklab/wp-git-action
|
||||
settings:
|
||||
action:
|
||||
- commit
|
||||
- push
|
||||
author_email: ci-bot@rknet.org
|
||||
author_name: ci-bot
|
||||
branch: main
|
||||
message: "[skip ci] automated docs update"
|
||||
netrc_machine: gitea.rknet.org
|
||||
netrc_password:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
depends_on:
|
||||
- test
|
30
.woodpecker/lint.yaml
Normal file
30
.woodpecker/lint.yaml
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request, tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
- name: ansible-lint
|
||||
image: quay.io/thegeeklab/ansible-dev-tools:1
|
||||
commands:
|
||||
- ansible-lint
|
||||
environment:
|
||||
FORCE_COLOR: "1"
|
||||
|
||||
- name: python-format
|
||||
image: docker.io/python:3.12
|
||||
commands:
|
||||
- pip install -qq ruff
|
||||
- ruff format --check --diff .
|
||||
environment:
|
||||
PY_COLORS: "1"
|
||||
|
||||
- name: python-lint
|
||||
image: docker.io/python:3.12
|
||||
commands:
|
||||
- pip install -qq ruff
|
||||
- ruff check .
|
||||
environment:
|
||||
PY_COLORS: "1"
|
26
.woodpecker/notify.yml
Normal file
26
.woodpecker/notify.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
when:
|
||||
- event: [tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
runs_on: [success, failure]
|
||||
|
||||
steps:
|
||||
- name: matrix
|
||||
image: quay.io/thegeeklab/wp-matrix
|
||||
settings:
|
||||
homeserver:
|
||||
from_secret: matrix_homeserver
|
||||
room_id:
|
||||
from_secret: matrix_room_id
|
||||
user_id:
|
||||
from_secret: matrix_user_id
|
||||
access_token:
|
||||
from_secret: matrix_access_token
|
||||
when:
|
||||
- status: [failure]
|
||||
|
||||
depends_on:
|
||||
- docs
|
24
.woodpecker/test.yaml
Normal file
24
.woodpecker/test.yaml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request, tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
variables:
|
||||
- &molecule_base
|
||||
image: quay.io/thegeeklab/ansible-dev-tools:1
|
||||
group: molecule
|
||||
environment:
|
||||
PY_COLORS: "1"
|
||||
HCLOUD_TOKEN:
|
||||
from_secret: molecule_hcloud_token
|
||||
|
||||
steps:
|
||||
- name: molecule-default
|
||||
<<: *molecule_base
|
||||
commands:
|
||||
- molecule test -s default
|
||||
|
||||
depends_on:
|
||||
- lint
|
20
.yamllint
Normal file
20
.yamllint
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
extends: default
|
||||
|
||||
rules:
|
||||
truthy:
|
||||
allowed-values: ["True", "False"]
|
||||
comments:
|
||||
min-spaces-from-content: 1
|
||||
comments-indentation: False
|
||||
line-length: disable
|
||||
braces:
|
||||
min-spaces-inside: 0
|
||||
max-spaces-inside: 1
|
||||
brackets:
|
||||
min-spaces-inside: 0
|
||||
max-spaces-inside: 0
|
||||
indentation: enable
|
||||
octal-values:
|
||||
forbid-implicit-octal: True
|
||||
forbid-explicit-octal: True
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Robert Kaussow <mail@thegeeklab.de>
|
||||
|
||||
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 (including the next
|
||||
paragraph) 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.
|
78
README.md
Normal file
78
README.md
Normal file
@ -0,0 +1,78 @@
|
||||
# xoxys.smb
|
||||
|
||||
[![Build Status](https://ci.rknet.org/api/badges/ansible/xoxys.smb/status.svg)](https://ci.rknet.org/repos/ansible/xoxys.smb)
|
||||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](https://gitea.rknet.org/ansible/xoxys.smb/src/branch/main/LICENSE)
|
||||
|
||||
Mount a list of Samba shares.
|
||||
|
||||
## Table of content
|
||||
|
||||
- [Requirements](#requirements)
|
||||
- [Default Variables](#default-variables)
|
||||
- [smb_packages](#smb_packages)
|
||||
- [smb_shares](#smb_shares)
|
||||
- [Dependencies](#dependencies)
|
||||
- [License](#license)
|
||||
- [Author](#author)
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
|
||||
- Minimum Ansible version: `2.10`
|
||||
|
||||
## Default Variables
|
||||
|
||||
### smb_packages
|
||||
|
||||
#### Default value
|
||||
|
||||
```YAML
|
||||
smb_packages:
|
||||
- cifs-utils
|
||||
```
|
||||
|
||||
### smb_shares
|
||||
|
||||
Mount defined samba shares. You can specify samba credentials with the
|
||||
`username` and `password` parameter. Given credentials will be used in a secrets file
|
||||
and saved to `/root/.smbcredentials/<name>` instead of the direct use in `/etc/fstab`.
|
||||
If secrets are defined for a list item, the secrest file will also be passed automatically
|
||||
to `mountopts`.
|
||||
|
||||
The `state` parameter is related to the possible state values of Ansibles
|
||||
[mount](https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html) module.
|
||||
|
||||
#### Default value
|
||||
|
||||
```YAML
|
||||
smb_shares: []
|
||||
```
|
||||
|
||||
#### Example usage
|
||||
|
||||
```YAML
|
||||
smb_shares:
|
||||
- name: multimedia
|
||||
source: //share.example.com/media
|
||||
username: myuser
|
||||
password: secure
|
||||
mountpoint: /media/data
|
||||
mountopts:
|
||||
- acl
|
||||
- uid=1000
|
||||
- gid=1000
|
||||
state: mounted
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
None.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Author
|
||||
|
||||
[Robert Kaussow](https://gitea.rknet.org/xoxys)
|
29
defaults/main.yml
Normal file
29
defaults/main.yml
Normal file
@ -0,0 +1,29 @@
|
||||
---
|
||||
smb_packages:
|
||||
- cifs-utils
|
||||
|
||||
# @var smb_shares:description: >
|
||||
# Mount defined samba shares. You can specify samba credentials with the
|
||||
# `username` and `password` parameter. Given credentials will be used in a secrets file
|
||||
# and saved to `/root/.smbcredentials/<name>` instead of the direct use in `/etc/fstab`.
|
||||
# If secrets are defined for a list item, the secrest file will also be passed automatically
|
||||
# to `mountopts`.
|
||||
#
|
||||
# The `state` parameter is related to the possible state values of Ansibles
|
||||
# [mount](https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html) module.
|
||||
# @end
|
||||
|
||||
# @var smb_shares:example: >
|
||||
# smb_shares:
|
||||
# - name: multimedia
|
||||
# source: //share.example.com/media
|
||||
# username: myuser
|
||||
# password: secure
|
||||
# mountpoint: /media/data
|
||||
# mountopts:
|
||||
# - acl
|
||||
# - uid=1000
|
||||
# - gid=1000
|
||||
# state: mounted
|
||||
# @end
|
||||
smb_shares: []
|
24
meta/main.yml
Normal file
24
meta/main.yml
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
galaxy_info:
|
||||
# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys)
|
||||
author: Robert Kaussow <mail@thegeeklab.de>
|
||||
namespace: xoxys
|
||||
role_name: smb
|
||||
# @meta description: >
|
||||
# [![Build Status](https://ci.rknet.org/api/badges/ansible/xoxys.smb/status.svg)](https://ci.rknet.org/repos/ansible/xoxys.smb)
|
||||
# [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](https://gitea.rknet.org/ansible/xoxys.smb/src/branch/main/LICENSE)
|
||||
#
|
||||
# Mount a list of Samba shares.
|
||||
# @end
|
||||
description: Mount a list of Samba shares
|
||||
license: MIT
|
||||
min_ansible_version: "2.10"
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- "9"
|
||||
galaxy_tags:
|
||||
- storage
|
||||
- smb
|
||||
- samba
|
||||
dependencies: []
|
15
molecule/default/converge.yml
Normal file
15
molecule/default/converge.yml
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
smb_shares:
|
||||
- name: multimedia
|
||||
source: //share.example.com/media
|
||||
username: myuser
|
||||
password: secure
|
||||
mountpoint: /media/data
|
||||
mountopts:
|
||||
- acl
|
||||
state: present
|
||||
roles:
|
||||
- role: xoxys.smb
|
17
molecule/default/molecule.yml
Normal file
17
molecule/default/molecule.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
driver:
|
||||
name: molecule_hetznercloud
|
||||
dependency:
|
||||
name: galaxy
|
||||
options:
|
||||
role-file: requirements.yml
|
||||
requirements-file: requirements.yml
|
||||
platforms:
|
||||
- name: "rocky9-smb"
|
||||
server_type: "cx22"
|
||||
image: "rocky-9"
|
||||
provisioner:
|
||||
name: ansible
|
||||
log: False
|
||||
verifier:
|
||||
name: testinfra
|
11
molecule/default/prepare.yml
Normal file
11
molecule/default/prepare.yml
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: False
|
||||
tasks:
|
||||
- name: Bootstrap Python for Ansible
|
||||
ansible.builtin.raw: |
|
||||
command -v python3 python ||
|
||||
((test -e /usr/bin/apt && (apt -y update && apt install -y python-minimal)) ||
|
||||
echo "Warning: Python not boostrapped due to unknown platform.")
|
||||
changed_when: False
|
19
molecule/default/tests/test_default.py
Normal file
19
molecule/default/tests/test_default.py
Normal file
@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
import testinfra.utils.ansible_runner
|
||||
|
||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||
os.environ["MOLECULE_INVENTORY_FILE"]
|
||||
).get_hosts("all")
|
||||
|
||||
|
||||
def test_smb_in_fstab(host):
|
||||
fstab = host.file("/etc/fstab")
|
||||
assert fstab.contains("//share.example.com/media")
|
||||
|
||||
|
||||
def test_smb_credentials(host):
|
||||
credentials = host.file("/root/.smbcredentials/multimedia")
|
||||
assert credentials.exists
|
||||
assert credentials.contains("username=myuser")
|
||||
assert credentials.contains("password=secure")
|
17
pyproject.toml
Normal file
17
pyproject.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[tool.ruff]
|
||||
exclude = [".git", "__pycache__"]
|
||||
|
||||
line-length = 99
|
||||
indent-width = 4
|
||||
|
||||
[tool.ruff.lint]
|
||||
ignore = ["W191", "E111", "E114", "E117", "S101", "S105"]
|
||||
select = ["F", "E", "I", "W", "S"]
|
||||
|
||||
[tool.ruff.format]
|
||||
quote-style = "double"
|
||||
indent-style = "space"
|
||||
line-ending = "lf"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
filterwarnings = ["ignore::FutureWarning", "ignore::DeprecationWarning"]
|
4
requirements.yml
Normal file
4
requirements.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
collections: []
|
||||
|
||||
roles: []
|
35
tasks/main.yml
Normal file
35
tasks/main.yml
Normal file
@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Install requirements
|
||||
ansible.builtin.package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop: "{{ smb_packages }}"
|
||||
|
||||
- name: Ensure credentials folder exist
|
||||
ansible.builtin.file:
|
||||
path: /root/.smbcredentials
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
state: directory
|
||||
|
||||
- name: Create secrets file
|
||||
ansible.builtin.template:
|
||||
src: "smbcredentials.j2"
|
||||
dest: "/root/.smbcredentials/{{ item.name }}"
|
||||
mode: "0600"
|
||||
loop: "{{ smb_shares }}"
|
||||
loop_control:
|
||||
label: "/root/.smbcredentials/{{ item.name }}"
|
||||
when: item.password is defined and item.password
|
||||
|
||||
- name: Mount volume
|
||||
ansible.posix.mount:
|
||||
path: "{{ item.mountpoint }}"
|
||||
src: "{{ item.source }}"
|
||||
fstype: "cifs"
|
||||
opts: "{{ ((item.mountopts | default([])) if not (item.password is defined and item.password) else ((item.mountopts | default([])) + ['credentials=/root/.smbcredentials/' + item.name])) | join(',') }}"
|
||||
state: "{{ item.state | default('mounted') }}"
|
||||
loop: "{{ smb_shares }}"
|
||||
loop_control:
|
||||
label: "mount: {{ item.source }} {{ item.mountpoint }} cifs {% if item.mountopts is defined %}{{ item.mountopts | join(',') }}{% endif %}"
|
2
templates/smbcredentials.j2
Normal file
2
templates/smbcredentials.j2
Normal file
@ -0,0 +1,2 @@
|
||||
username={{ item.username }}
|
||||
password={{ item.password }}
|
Loading…
Reference in New Issue
Block a user