From 764cbfe0f2ff4f71be99f34ee9ba03fd21bb1002 Mon Sep 17 00:00:00 2001 From: Luigi Cruz Date: Fri, 7 May 2021 17:21:57 -0300 Subject: [PATCH] Improve mounting. --- ansible/tasks/mount.yaml | 21 +++++++++++++++++---- ansible/tasks/umount.yaml | 3 +-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ansible/tasks/mount.yaml b/ansible/tasks/mount.yaml index 573a04d..b39598d 100644 --- a/ansible/tasks/mount.yaml +++ b/ansible/tasks/mount.yaml @@ -2,7 +2,20 @@ - name: Mount pseudo filesystems connection: local shell: | - mount -o bind,ro /dev {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/dev - mount -o bind,ro /dev/pts {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/dev/pts - mount -t proc none {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/proc - mount -t sysfs none {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/sys \ No newline at end of file + ROOTFS_DIR={{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }} + + if grep -q "$(realpath "${ROOTFS_DIR}"/proc)"; then + mount -t proc proc "${ROOTFS_DIR}/proc" + fi + + if grep -q "$(realpath "${ROOTFS_DIR}"/dev)"; then + mount --bind /dev "${ROOTFS_DIR}/dev" + fi + + if grep -q "$(realpath "${ROOTFS_DIR}"/dev/pts)"; then + mount --bind /dev/pts "${ROOTFS_DIR}/dev/pts" + fi + + if grep -q "$(realpath "${ROOTFS_DIR}"/sys)"; then + mount --bind /sys "${ROOTFS_DIR}/sys" + fi \ No newline at end of file diff --git a/ansible/tasks/umount.yaml b/ansible/tasks/umount.yaml index 3a3ca58..3b60320 100644 --- a/ansible/tasks/umount.yaml +++ b/ansible/tasks/umount.yaml @@ -1,8 +1,7 @@ --- - name: Umount pseudo filesystems connection: local - shell: umount -l '{{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}{{ item }}' - ignore_errors: yes + shell: umount '{{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}{{ item }}' with_items: - /proc - /dev/pts