Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active December 11, 2021 05:08
Show Gist options
  • Select an option

  • Save halberom/8f22f58f56c142c1f142a65bdf5f6cff to your computer and use it in GitHub Desktop.

Select an option

Save halberom/8f22f58f56c142c1f142a65bdf5f6cff to your computer and use it in GitHub Desktop.

Revisions

  1. Gerard Lynch revised this gist Aug 1, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 03_play.yml
    Original file line number Diff line number Diff line change
    @@ -26,5 +26,5 @@
    src: "{{ item.disk.dev }}"
    fstype: ntfs
    when: "item.partitions | length > 0 and item.partitions | selectattr('fstype', 'equalto', 'ntfs') | list | length > 0"
    with_items: "{{ driveFStype }}"
    with_items: "{{ driveFStype.results }}"

  2. Gerard Lynch revised this gist Aug 1, 2017. 1 changed file with 30 additions and 0 deletions.
    30 changes: 30 additions & 0 deletions 03_play.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    ---
    - hosts: localhost
    connection: local
    gather_facts: False
    tasks:
    - setup:
    filter: ansible_devices

    # - include_vars: jsonfile.json

    # - name: Check for partitions on disk devices
    # parted:
    # device: "/dev/{{ item.key }}"
    # unit: MiB
    # when: item.partitions | length > 0
    # with_dict: "{{ ansible_devices }}"
    # register: driveFStype

    - include_vars:
    path: 01_parted.json
    name: driveFStype

    - name: mount ntfs partitions
    mount:
    path: "/mnt/{{ item.item }}"
    src: "{{ item.disk.dev }}"
    fstype: ntfs
    when: "item.partitions | length > 0 and item.partitions | selectattr('fstype', 'equalto', 'ntfs') | list | length > 0"
    with_items: "{{ driveFStype }}"

  3. Gerard Lynch created this gist Aug 1, 2017.
    31 changes: 31 additions & 0 deletions 00_play.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    ---
    - hosts: localhost
    connection: local
    gather_facts: False
    tasks:
    # - include_vars: jsonfile.json
    #
    # - debug:
    # var: ansible_devices
    #
    # - debug:
    # var: item.value.partitions
    # when: "item.value.partitions | length > 0"
    # with_dict: "{{ ansible_devices }}"
    #
    # - name: Check for partitions on disk devices
    # parted:
    # device: "/dev/{{ item.key }}"
    # unit: MiB
    # when: item.partitions | length > 0
    # with_dict: "{{ ansible_devices }}"
    # register: driveFStype

    - include_vars: 01_parted.json

    - debug:
    msg: "{{ results | json_query(query) }}"
    vars:
    query: "[].{disk: disk.dev, partitions: partitions[?fstype=='ntfs']}"
    #query: "[].disk.dev"

    88 changes: 88 additions & 0 deletions 01_parted.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    "results": [
    {
    "_ansible_item_result": true,
    "_ansible_no_log": false,
    "_ansible_parsed": true,
    "changed": false,
    "disk": {
    "dev": "/dev/sda2",
    "logical_block": 512,
    "model": "Unknown",
    "physical_block": 512,
    "size": 32466.0,
    "table": "loop",
    "unit": "mib"
    },
    "invocation": {
    "module_args": {
    "align": "optimal",
    "device": "/dev/sda2",
    "flags": null,
    "label": null,
    "name": null,
    "number": null,
    "part_end": "100%",
    "part_start": "0%",
    "part_type": "primary",
    "state": "info",
    "unit": "MiB"
    }
    },
    "item": "sda2",
    "partitions": [
    {
    "begin": 0.0,
    "end": 32466.0,
    "flags": [],
    "fstype": "ntfs",
    "num": 1,
    "size": 32466.0,
    "unit": "mib"
    }
    ],
    "script": "unit 'MiB' print"
    },
    {
    "_ansible_item_result": true,
    "_ansible_no_log": false,
    "_ansible_parsed": true,
    "changed": false,
    "disk": {
    "dev": "/dev/sda1",
    "logical_block": 512,
    "model": "Unknown",
    "physical_block": 512,
    "size": 300.0,
    "table": "loop",
    "unit": "mib"
    },
    "invocation": {
    "module_args": {
    "align": "optimal",
    "device": "/dev/sda1",
    "flags": null,
    "label": null,
    "name": null,
    "number": null,
    "part_end": "100%",
    "part_start": "0%",
    "part_type": "primary",
    "state": "info",
    "unit": "MiB"
    }
    },
    "item": "sda1",
    "partitions": [
    {
    "begin": 0.0,
    "end": 300.0,
    "flags": [],
    "fstype": "ntfs",
    "num": 1,
    "size": 300.0,
    "unit": "mib"
    }
    ],
    "script": "unit 'MiB' print"
    }
    ]
    41 changes: 41 additions & 0 deletions 02_output
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    PLAY [localhost] **********************************************************************************************************************

    TASK [include_vars] *******************************************************************************************************************
    ok: [localhost]

    TASK [debug] **************************************************************************************************************************
    ok: [localhost] => {
    "msg": [
    {
    "disk": "/dev/sda2",
    "partitions": [
    {
    "begin": 0.0,
    "end": 32466.0,
    "flags": [],
    "fstype": "ntfs",
    "num": 1,
    "size": 32466.0,
    "unit": "mib"
    }
    ]
    },
    {
    "disk": "/dev/sda1",
    "partitions": [
    {
    "begin": 0.0,
    "end": 300.0,
    "flags": [],
    "fstype": "ntfs",
    "num": 1,
    "size": 300.0,
    "unit": "mib"
    }
    ]
    }
    ]
    }

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