title: How to get unmounted device from Ansible facts
body: <p>I would like to implement such demands via Ansible playbook
  1. Get Ansible host facts
  2. Run through "ansible_mounts.device" using ansible_device
  3. If any device is not in ansible.mounts.device then print them into a file. </p>
  
  <p>Below is my playbook:</p>
  
  <pre><code>- hosts: all
    become: true
    tasks:
    - name: list all mounted device
      shell: /bin/echo {{ item.device }} &gt;&gt; /root/mounted
      with_items: "{{ ansible_mounts }}"
      register: mounted_device
    - name: list all umount disks
      shell: /bin/echo {{ item }}
      with_items: "{{ ansible_devices.keys() }}"
      when: '{{ item }} not in {{ mounted_device }} '
  </code></pre>
  
  <p>However, the mounted_device is always a list of all information in ansible_mounts element which I thought it should be list of devices like "/dev/xvda1". Actually, in /root/mounted it <em>is</em> "/dev/xvda1"</p>
  
  <p>Can anyone please help with this? Or is there any more brilliant way to achieve the goal? </p>