Skip to content

Instantly share code, notes, and snippets.

@alxschwarz
Last active February 21, 2017 13:11
Show Gist options
  • Save alxschwarz/86c7fe6743acdab229df484a62df5fef to your computer and use it in GitHub Desktop.
Save alxschwarz/86c7fe6743acdab229df484a62df5fef to your computer and use it in GitHub Desktop.
ansible: getting disks on instance
- hosts: localhost
gather_facts: no
tasks:
- name: Get list of disks on instance
shell: "/bin/lsblk -l |grep disk|awk '{print $1}'"
register: disks
- debug: var=item
with_items: "{{ disks.stdout.split('\n') }}"
@alxschwarz
Copy link
Author

Sample output:

[WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] ***************************************************************

TASK [Get list of disks on instance] *******************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => (item=sda) => {
    "item": "sda"
}
ok: [localhost] => (item=nvme0n2) => {
    "item": "nvme0n2"
}
ok: [localhost] => (item=nvme0n1) => {
    "item": "nvme0n1"
}
ok: [localhost] => (item=nvme0n3) => {
    "item": "nvme0n3"
}
ok: [localhost] => (item=nvme0n4) => {
    "item": "nvme0n4"
}
ok: [localhost] => (item=nvme0n5) => {
    "item": "nvme0n5"
}
ok: [localhost] => (item=nvme0n6) => {
    "item": "nvme0n6"
}
ok: [localhost] => (item=nvme0n7) => {
    "item": "nvme0n7"
}
ok: [localhost] => (item=nvme0n8) => {
    "item": "nvme0n8"
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment