add cifsmount role
This commit is contained in:
85
README.md
Normal file
85
README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
ansible-role-cifs
|
||||
=================
|
||||
|
||||
Mount any cifs network share and create a persistent config.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
An available cifs network share.
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
```yaml
|
||||
# share configs, this can be a list of shares
|
||||
cifs_connections:
|
||||
- name: movies
|
||||
user: testuser
|
||||
pass: changeme
|
||||
mountpoint: '/movies'
|
||||
domain: mymediaserver.com
|
||||
share: 'O:\\some\weird\windows\share'
|
||||
- name: pictures
|
||||
user: testuser
|
||||
pass: changeme
|
||||
mountpoint: '/pictures'
|
||||
domain: mymediaserver.com
|
||||
share: 'O:\\some\weird\windows\share'
|
||||
|
||||
# local
|
||||
cifs_credsfile_path: '/root'
|
||||
cifs_credsfile_mode: '0600'
|
||||
cifs_credsfile_owner: root
|
||||
cifs_mount_root_path: '/mnt'
|
||||
cifs_dir_mode: '0777'
|
||||
cifs_file_mode: '0777'
|
||||
cifs_persist_config: false
|
||||
```
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
None.
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
An example playbook which installs all necessary packages and configures
|
||||
all the shares defined in the list `cifs_connections`.
|
||||
|
||||
|
||||
```yaml
|
||||
---
|
||||
|
||||
- name: cifs test play
|
||||
hosts: all
|
||||
vars:
|
||||
cifs_persist_config: false
|
||||
cifs_connections:
|
||||
- name: movies
|
||||
user: testuser
|
||||
pass: changeme
|
||||
mountpoint: '/movies'
|
||||
domain: mymediaserver.com
|
||||
share: 'O:\\some\weird\windows\share'
|
||||
- name: pictures
|
||||
user: testuser
|
||||
pass: changeme
|
||||
mountpoint: '/pictures'
|
||||
domain: mymediaserver.com
|
||||
share: 'O:\\some\weird\windows\share'
|
||||
roles:
|
||||
- cifs
|
||||
```
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
GPLv3
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
Aaron (aaron@0x29a.ch)
|
||||
19
defaults/main.yml
Normal file
19
defaults/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
|
||||
# share configs
|
||||
cifs_connections:
|
||||
- name: webshop
|
||||
user: shareuser
|
||||
pass: changeme
|
||||
mountpoint: '/share'
|
||||
domain: myshare.com
|
||||
share: 'O:\\some\weird\windows\share'
|
||||
|
||||
# local
|
||||
cifs_credsfile_path: '/root'
|
||||
cifs_credsfile_mode: '0600'
|
||||
cifs_credsfile_owner: root
|
||||
cifs_mount_root_path: '/mnt'
|
||||
cifs_dir_mode: '0777'
|
||||
cifs_file_mode: '0777'
|
||||
cifs_persist_config: false
|
||||
1
handlers/main.yml
Normal file
1
handlers/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
---
|
||||
53
meta/main.yml
Normal file
53
meta/main.yml
Normal file
@@ -0,0 +1,53 @@
|
||||
galaxy_info:
|
||||
author: your name
|
||||
description: your role description
|
||||
company: your company (optional)
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Choose a valid license ID from https://spdx.org - some suggested licenses:
|
||||
# - BSD-3-Clause (default)
|
||||
# - MIT
|
||||
# - GPL-2.0-or-later
|
||||
# - GPL-3.0-only
|
||||
# - Apache-2.0
|
||||
# - CC-BY-4.0
|
||||
license: license (GPL-2.0-or-later, MIT, etc)
|
||||
|
||||
min_ansible_version: 2.9
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
#
|
||||
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||
# To view available platforms and versions (or releases), visit:
|
||||
# https://galaxy.ansible.com/api/v1/platforms/
|
||||
#
|
||||
# platforms:
|
||||
# - name: Fedora
|
||||
# versions:
|
||||
# - all
|
||||
# - 25
|
||||
# - name: SomePlatform
|
||||
# versions:
|
||||
# - all
|
||||
# - 1.0
|
||||
# - 7
|
||||
# - 99.99
|
||||
|
||||
galaxy_tags: []
|
||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
||||
|
||||
23
tasks/configuration.yaml
Normal file
23
tasks/configuration.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: push samba credentials for each configured connection
|
||||
template:
|
||||
src: smbcredentials.j2
|
||||
dest: '{{ cifs_credsfile_path }}/.smbcredentials_{{ item.name }}'
|
||||
owner: '{{ cifs_credsfile_owner }}'
|
||||
mode: '{{ cifs_credsfile_mode }}'
|
||||
vars:
|
||||
cifs_user: '{{ item.user }}'
|
||||
cifs_pass: '{{ item.pass }}'
|
||||
cifs_domain: '{{ item.domain | upper }}'
|
||||
loop: '{{ cifs_connections }}'
|
||||
|
||||
- name: mount shared drive and persist configuration to fstab
|
||||
mount:
|
||||
fstype: cifs
|
||||
state: mounted
|
||||
path: '{{ cifs_mount_root_path }}/{{ item.name }}'
|
||||
opts: 'credentials={{ cifs_credsfile_path }}/.smbcredentials_{{ item.name }},file_mode={{ cifs_file_mode }},dir_mode={{ cifs_dir_mode }}'
|
||||
src: '{{ item.share }}'
|
||||
loop: '{{ cifs_connections }}'
|
||||
when: cifs_persist_config == true
|
||||
6
tasks/installation.yaml
Normal file
6
tasks/installation.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
- name: install all components for a working cifs mount
|
||||
package:
|
||||
name: '{{ cifs_packages }}'
|
||||
state: present
|
||||
19
tasks/main.yaml
Normal file
19
tasks/main.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
|
||||
- name: load variables based on distribution type
|
||||
include_vars: '{{ item }}'
|
||||
with_first_found:
|
||||
- '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yaml'
|
||||
- '{{ ansible_os_family }}.yaml'
|
||||
tags:
|
||||
- 'cifs_vars'
|
||||
|
||||
- name: install cifs and dependencies
|
||||
import_tasks: installation.yaml
|
||||
tags:
|
||||
- 'cifs_installation'
|
||||
|
||||
- name: push cifs config
|
||||
import_tasks: configuration.yaml
|
||||
tags:
|
||||
- 'cifs_configuration'
|
||||
3
templates/smbcredentials.j2
Normal file
3
templates/smbcredentials.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
username={{ cifs_user }}
|
||||
password={{ cifs_pass }}
|
||||
domain={{ cifs_domain }}
|
||||
2
tests/inventory
Normal file
2
tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
||||
5
tests/test.yml
Normal file
5
tests/test.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- ansible-role-cifsmount
|
||||
6
vars/RedHat.yaml
Normal file
6
vars/RedHat.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
cifs_packages:
|
||||
- samba-common
|
||||
- samba-client
|
||||
- cifs-utils
|
||||
Reference in New Issue
Block a user