This isn't tested.  I ran it successfully for a single known added disk of 
/dev/vdb.  But take a look and it might help:
- name: "finding recent added device"
  shell: bash -c 'comm -23 <(lsblk -l | grep disk | cut -f1 -d" ") <(lsblk 
-l | grep part | cut -c1-3 | uniq)'
  register: fdisk
- debug:
     msg: "New disks are {{fdisk.stdout_lines}}"
- name: partition check
  parted:
    device: "/dev/{{item}}"
    unit: GiB
  register: "{{ item }}"_info
  with_items:
    - "{{fdisk.stdout_lines}}"
- name: partition drive
  parted:
    device: "/dev/{{item}}"
    number: 1
    label: gpt
    part_start: 0%
    part_end: 100%
    name: "{{ item }}"-pv
    state: present
  with_items:
    - "{{fdisk.stdout_lines}}"
  when: {{item}}_info.disk.table == "unknown"
- name: make-volg
  lvg:
    vg: "{{vg_name}}"
    pvs: "/dev/{{item}}1"
    pesize: 32
  with_items:
     - "{{fdisk.stdout_lines}}"



On Sunday, September 30, 2018 at 10:57:12 AM UTC-4, [email protected] 
wrote:

> HI all,
>
>  I am trying to get the disk information of target machine.
>
> 1. I want to check the newly added disk which is fully free, means there 
> is no partition created.
> 2. running a loop like /dev/sda to /dev/sdz and that should fail if 
> patition is not created and print the me last failed disk. can someone help 
> me ?
>
> I have tried bellow playbook in Linux machine. let me know the changes.
>
> Thanks in advance.
>
> - hosts: one
>   become: true
>   tasks:
>     - shell: " lsblk | grep -i disk | awk '{print$1}' "
>       register: part
>     - debug:
>          msg: "{{part.stdout_lines}}"
>     - shell: "fdisk -l /dev/{{item}}1 | grep -i cylinders"
>       register: new
>       with_items:
>          - "{{part.stdout_lines}}"
>       #until: '"cylinders" not in new.stdout'
>       failed_when: new.rc == 1
>       ignore_errors: true
>     - debug:
>          msg: "{{item.new}}"
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/89c02344-fb9c-4ab7-a6d6-d5f6ec4ced8f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to