xci: playbooks: configure-nfs: Prepare for multi-distro support 21/40121/5
authorMarkos Chandras <mchandras@suse.de>
Thu, 24 Aug 2017 12:50:55 +0000 (13:50 +0100)
committerMarkos Chandras <mchandras@suse.de>
Fri, 25 Aug 2017 20:50:15 +0000 (20:50 +0000)
There is nothing Ubuntu specific in this role apart from the nfs server
service name. As such we remove the block statement and make the service
name configurable in order to prepare for multidistribution support.

Change-Id: I3c8202315fc49b5e5afc2a0d03eaf80d83db5f4c
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/playbooks/roles/configure-nfs/tasks/main.yml
xci/playbooks/roles/configure-nfs/vars/debian.yml [new file with mode: 0644]

index c52da0b..51a2d43 100644 (file)
@@ -7,37 +7,43 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-# TODO: this is for xenial and needs to be adjusted for different distros
-- block:
-    - name: make NFS directories
-      file:
-        dest: "{{ item }}"
-        mode: 0777
-        state: directory
-      with_items:
-        - "/images"
-        - "/volumes"
-    - name: configure NFS service
-      lineinfile:
-        dest: /etc/services
-        state: present
-        create: yes
-        line: "{{ item }}"
-      with_items:
-        - "nfs        2049/tcp"
-        - "nfs        2049/udp"
-    - name: configure NFS exports
-      lineinfile:
-        dest: /etc/exports
-        state: present
-        create: yes
-        line: "{{ item }}"
-      with_items:
-        - "/images         *(rw,sync,no_subtree_check,no_root_squash)"
-        - "/volumes        *(rw,sync,no_subtree_check,no_root_squash)"
-    # TODO: the service name might be different on other distros and needs to be adjusted
-    - name: restart ubuntu xenial NFS service
-      service:
-        name: nfs-kernel-server
-        state: restarted
-  when: ansible_distribution_release == "xenial"
+
+- name: Gather variables for each operating system
+  include_vars: "{{ item }}"
+  with_first_found:
+    - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
+    - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
+    - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
+    - "{{ ansible_distribution | lower }}.yml"
+    - "{{ ansible_os_family | lower }}.yml"
+- name: make NFS directories
+  file:
+    dest: "{{ item }}"
+    mode: 0777
+    state: directory
+  with_items:
+    - "/images"
+    - "/volumes"
+- name: configure NFS service
+  lineinfile:
+    dest: /etc/services
+    state: present
+    create: yes
+    line: "nfs    2049/{{ item }}"
+    regexp: "^[[:space:]]*nfs[[:space:]]*2049/{{ item }}"
+  with_items:
+    - "tcp"
+    - "udp"
+- name: configure NFS exports
+  lineinfile:
+    dest: /etc/exports
+    state: present
+    create: yes
+    line: "{{ item }}"
+  with_items:
+    - "/images         *(rw,sync,no_subtree_check,no_root_squash)"
+    - "/volumes        *(rw,sync,no_subtree_check,no_root_squash)"
+- name: restart ubuntu xenial NFS service
+  service:
+    name: "{{ nfs_server_service }}"
+    state: restarted
diff --git a/xci/playbooks/roles/configure-nfs/vars/debian.yml b/xci/playbooks/roles/configure-nfs/vars/debian.yml
new file mode 100644 (file)
index 0000000..8d3c656
--- /dev/null
@@ -0,0 +1,11 @@
+---
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2017 Ericsson AB and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+nfs_server_service: "nfs-kernel-server"