From 35bd4e825a0c31bbf88300bb9e6ab2564234e97a Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Mon, 18 May 2015 13:09:52 -0500 Subject: [PATCH] cobbler_profile: use the mount module instead of command to mount isos The mount module is idempotent, so we should use that instead. Also, clear the mount point each time so that if the playbook fails on the next run it'll actually remount and complete the rest of the tasks instead of skipping them because the iso is already mounted. Signed-off-by: Andrew Schoen --- roles/cobbler_profile/tasks/import_distro.yml | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/roles/cobbler_profile/tasks/import_distro.yml b/roles/cobbler_profile/tasks/import_distro.yml index 6ab3cbd..7300a4a 100644 --- a/roles/cobbler_profile/tasks/import_distro.yml +++ b/roles/cobbler_profile/tasks/import_distro.yml @@ -31,8 +31,24 @@ - include: download_iso.yml when: distro.iso != '' +# we do this so that if the playbook fails +# after mounting and we need to run it again +# then we'll remount and complete the rest +# of the tasks like it's the first run +- name: Clear the mount point. + mount: + name: "{{ iso_mount }}" + src: "{{ iso_path }}" + fstype: "iso9660" + state: unmounted + - name: Mount ISO - command: mount -o loop {{ iso_path }} {{ iso_mount }} + mount: + name: "{{ iso_mount }}" + src: "{{ iso_path }}" + opts: "loop" + fstype: "iso9660" + state: mounted when: download|changed or (iso_stat.stat.exists and profile is defined and profile.stdout == '') register: mount @@ -40,16 +56,20 @@ - name: Set arch set_fact: arch: "{{ distro.arch|default('x86_64') }}" - when: mount is defined and mount.rc == 0 + when: mount is defined and mount|changed - name: Import the distro (also creates the profile) command: cobbler import --path={{ iso_mount }} --name={{ distro_name }} --arch={{ arch }} register: import - when: mount is defined and mount.rc == 0 + when: mount is defined and mount|changed - name: Unmount ISO - command: umount {{ iso_mount }} - when: mount is defined and mount.rc == 0 + mount: + name: "{{ iso_mount }}" + src: "{{ iso_path }}" + fstype: "iso9660" + state: unmounted + when: mount is defined and mount|changed - name: Set kickstart path set_fact: -- 2.39.5