Pages

Monday, 30 December 2019

EX294: Modules for Storage devices

As far as I know, the only possible module for EX294 regarding Storage Devices now is "parted" which functions just like the command line tool with the same name.

0 Module 'parted'

  • maintained by the Ansible Community
  • not guaranteed to have a backward compatible interface
  • depends on "/sys"
  • "ansible-doc parted" for online help
  • needs escalated privilege

1 Examples

1.1 Get disk info

cat playbook.yml
---
- hosts: localhost
  tasks:
          - name: Get Disk Info of /dev/sda
            become: yes
            parted:
                    device: /dev/sda
                    state: info
            register: sda_info

          - name: Show
            debug: var=sda_info

$ ansible-playbook playbook.yml

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

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Get Disk Info of /dev/sda] ***********************************************
ok: [localhost]

TASK [Show] ********************************************************************
ok: [localhost] => {
    "sda_info": {
        "changed": false,
        "disk": {
            "dev": "/dev/sda",
            "logical_block": 512,
            "model": "VMware, VMware Virtual S",
            "physical_block": 512,
            "size": 41943040.0,
            "table": "msdos",
            "unit": "kib"
        },
        "failed": false,
        "partitions": [
            {
                "begin": 1024.0,
                "end": 1953792.0,
                "flags": [
                    "boot"
                ],
                "fstype": "ext2",
                "name": "",
                "num": 1,
                "size": 1952768.0,
                "unit": "kib"
            },
            {
                "begin": 1953792.0,
                "end": 33214464.0,
                "flags": [
                    "lvm"
                ],
                "fstype": "",
                "name": "",
                "num": 2,
                "size": 31260672.0,
                "unit": "kib"
            },
            {
                "begin": 33214464.0,
                "end": 41943040.0,
                "flags": [],
                "fstype": "",
                "name": "",
                "num": 3,
                "size": 8728576.0,
                "unit": "kib"
            }
        ],
        "script": "unit 'KiB' print"
    }
}

1.2 Create a new partition

$ cat playbook.yml
---
- hosts: localhost
  tasks:
          - name: create a new primary partition
            become: yes
            parted:
                    device: /dev/sda
                    number: 1
                    state: present

1.3 Delete a partition

cat playbook.yml
---
- hosts: localhost
  tasks:
          - name: Delete an existing partition
            become: yes
            parted:
                    device: /dev/sda
                    number: 1
                    state: absent

No comments:

Post a Comment