diff --git a/README.md b/README.md new file mode 100644 index 0000000..84d819b --- /dev/null +++ b/README.md @@ -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) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..050c938 --- /dev/null +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..227ad9c --- /dev/null +++ b/meta/main.yml @@ -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. + \ No newline at end of file diff --git a/tasks/configuration.yaml b/tasks/configuration.yaml new file mode 100644 index 0000000..9f48adc --- /dev/null +++ b/tasks/configuration.yaml @@ -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 diff --git a/tasks/installation.yaml b/tasks/installation.yaml new file mode 100644 index 0000000..76bcdff --- /dev/null +++ b/tasks/installation.yaml @@ -0,0 +1,6 @@ +--- + +- name: install all components for a working cifs mount + package: + name: '{{ cifs_packages }}' + state: present diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..90d77e9 --- /dev/null +++ b/tasks/main.yaml @@ -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' diff --git a/templates/smbcredentials.j2 b/templates/smbcredentials.j2 new file mode 100644 index 0000000..fdfc030 --- /dev/null +++ b/templates/smbcredentials.j2 @@ -0,0 +1,3 @@ +username={{ cifs_user }} +password={{ cifs_pass }} +domain={{ cifs_domain }} diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..6e92029 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-role-cifsmount diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..8ca9934 --- /dev/null +++ b/vars/RedHat.yaml @@ -0,0 +1,6 @@ +--- + +cifs_packages: + - samba-common + - samba-client + - cifs-utils