1

I have an Ubuntu server, with 2 drives /dev/sdb and /dev/sdc. The OS is installed under /dev/sdb. Now, I am trying to write an Ansible playbook which will identify whether the particular partition contains the OS. I tried using the lsblk command which returns that the drive /dev/sdb is partitioned. But no partition table exists for /dev/sdc/.

Any examples on how to achieve this? My current playbook looks like:

- hosts: localhost
  tasks:
   - name: Get list of mounted hard drives
     command: 'lsblk'
     register: result
   - name: Create variable block_devices
     set_fact:
       block_devices: "{{ result.stdout_lines }}"
   - debug:
       var: block_devices

This playbook returns the available partitions. From this output how to implement the OS installation check?

1 Answer 1

4

The rootfs is gathered in ansible_facts and does not need to be "extracted" via shell.

Here's how to access it:

# cat play.yml

---
- name: display rootfs partition
  hosts: all
  become: yes
  gather_facts: yes

  tasks:
   - name: print root partition
     shell: echo "{{ ansible_cmdline.root }}" > /tmp/rootfs_part
# ansible-playbook play.yml -i localhost,

PLAY [display rootfs partition] ******************************************************************************************************************************************************************************

TASK [print root partition] **********************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ***************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

# cat /tmp/rootfs_part
/dev/mapper/mirror-root

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .