summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Tyr <jtyr@users.noreply.github.com>2019-02-28 20:09:30 +0100
committerSam Doran <sdoran@redhat.com>2019-02-28 20:09:30 +0100
commit7739b5e96c3294fedcc2bf9cf695b7e51e072e62 (patch)
treebe1827c8586eeced6427d38265bf5c06b406fc49
parentDocumentation update for labels operations on swarm/node (#53083) (diff)
downloadansible-7739b5e96c3294fedcc2bf9cf695b7e51e072e62.tar.xz
ansible-7739b5e96c3294fedcc2bf9cf695b7e51e072e62.zip
Last two fields in fstab are optional (fixes #43855) (#43941)
* Last two fields in fstab are optional * Add changelog
-rw-r--r--changelogs/fragments/mount-optional-fields.yaml2
-rw-r--r--lib/ansible/modules/system/mount.py27
-rw-r--r--test/integration/targets/mount/tasks/main.yml32
3 files changed, 48 insertions, 13 deletions
diff --git a/changelogs/fragments/mount-optional-fields.yaml b/changelogs/fragments/mount-optional-fields.yaml
new file mode 100644
index 0000000000..c274371825
--- /dev/null
+++ b/changelogs/fragments/mount-optional-fields.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+ - mount - make last two fields optional (https://github.com/ansible/ansible/issues/43855)
diff --git a/lib/ansible/modules/system/mount.py b/lib/ansible/modules/system/mount.py
index 4313041ded..bb60d9b0ca 100644
--- a/lib/ansible/modules/system/mount.py
+++ b/lib/ansible/modules/system/mount.py
@@ -208,10 +208,14 @@ def set_mount(module, args):
continue
+ fields = line.split()
+
# Check if we got a valid line for splitting
+ # (on Linux the 5th and the 6th field is optional)
if (
- get_platform() == 'SunOS' and len(line.split()) != 7 or
- get_platform() != 'SunOS' and len(line.split()) != 6):
+ get_platform() == 'SunOS' and len(fields) != 7 or
+ get_platform() == 'Linux' and len(fields) not in [4, 5, 6] or
+ get_platform() not in ['SunOS', 'Linux'] and len(fields) != 6):
to_write.append(line)
continue
@@ -227,16 +231,17 @@ def set_mount(module, args):
ld['passno'],
ld['boot'],
ld['opts']
- ) = line.split()
+ ) = fields
else:
- (
- ld['src'],
- ld['name'],
- ld['fstype'],
- ld['opts'],
- ld['dump'],
- ld['passno']
- ) = line.split()
+ fields_labels = ['src', 'name', 'fstype', 'opts', 'dump', 'passno']
+
+ # The last two fields are optional on Linux so we fill in default values
+ ld['dump'] = 0
+ ld['passno'] = 0
+
+ # Fill in the rest of the available fields
+ for i, field in enumerate(fields):
+ ld[fields_labels[i]] = field
# Check if we found the correct line
if (
diff --git a/test/integration/targets/mount/tasks/main.yml b/test/integration/targets/mount/tasks/main.yml
index 6fdff8aac5..e8b7fdfbf8 100644
--- a/test/integration/targets/mount/tasks/main.yml
+++ b/test/integration/targets/mount/tasks/main.yml
@@ -119,8 +119,6 @@
shell: mount | grep mount_dest | grep -E -w '(ro|read-only)' | wc -l
register: remount_options
-- debug: var=remount_options
-
- name: Make sure the filesystem now has the new opts
assert:
that:
@@ -248,3 +246,33 @@
- "swap2_removed['changed']"
- "not swap2_removed_again['changed']"
when: ansible_system in ('Linux')
+
+- name: Create fstab record with missing last two fields
+ copy:
+ dest: /etc/fstab
+ content: |
+ //nas/photo /home/jik/pictures cifs defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev
+ when: ansible_system in ('Linux')
+
+- name: Try to change the fstab record with the missing last two fields
+ mount:
+ src: //nas/photo
+ path: /home/jik/pictures
+ fstype: cifs
+ opts: defaults,credentials=/etc/security/nas.creds,uid=jik,gid=users,forceuid,forcegid,noserverino,_netdev,x-systemd.mount-timeout=0
+ state: present
+ register: optional_fields_update
+ when: ansible_system in ('Linux')
+
+- name: Get the content of the fstab file
+ shell: cat /etc/fstab
+ register: optional_fields_content
+ when: ansible_system in ('Linux')
+
+- name: Check if the line containing the missing last two fields was changed
+ assert:
+ that:
+ - "optional_fields_update['changed']"
+ - "' 0 0' in optional_fields_content.stdout"
+ - "1 == optional_fields_content.stdout_lines | length"
+ when: ansible_system in ('Linux')