I have a task that mounts devices in a Linux machine.
I wish to run the task only if the device is not mounted, therefore I’m running a mount command and save the output in a register.
On the mount task, I’m trying to use when by searching the device in the register output - and I’m failing to do so.
The task is running even that /dev/sdb1 is included in the register
Playbook:
- name: check mount
shell: mount | awk '{print $1}'
register: mount
- debug:
msg: " {{ mount.stdout_lines }}"
- name: Mount task 1 - create directory
file:
path: "{{item.mount_path}}"
state: directory
when: mount.stdout_lines != "/dev/sdb1"
"state: If mounted, the device will be actively mounted and appropriately
configured in fstab. If the mount point is not present, the mount point
will be created."