Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Created September 17, 2020 10:26
Show Gist options
  • Save zeitounator/cb8a798f8913f401b374474fc4121dea to your computer and use it in GitHub Desktop.
Save zeitounator/cb8a798f8913f401b374474fc4121dea to your computer and use it in GitHub Desktop.
$ ansible --version
ansible 2.9.11
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
$ pip list | grep jmespath
jmespath 0.10.0
$ pip list | grep Jinja2
Jinja2 2.11.2
$ cat test.yml
---
- hosts: localhost
gather_facts: false
vars:
"nvme_output":
stdout: {
"Devices": [
{
"DevicePath": "/dev/nvme0n1",
"Firmware": "1.0",
"Index": 0,
"MaximumLBA": 33554432,
"ModelNumber": "Amazon Elastic Block Store",
"PhysicalSize": 17179869184,
"ProductName": "Non-Volatile memory controller: Vendor 0x1d0f Device 0x8061",
"SectorSize": 512,
"SerialNumber": "vol0e6af89fd1991cwtf",
"UsedBytes": 0
},
{
"DevicePath": "/dev/nvme1n1",
"Firmware": "1.0",
"Index": 1,
"MaximumLBA": 104857600,
"ModelNumber": "Amazon Elastic Block Store",
"PhysicalSize": 53687091200,
"ProductName": "Non-Volatile memory controller: Vendor 0x1d0f Device 0x8061",
"SectorSize": 512,
"SerialNumber": "vol0885625da4a60awtf",
"UsedBytes": 0
}
]
}
tasks:
- debug:
var: nvme_output.stdout
- debug:
msg: "{{ nvme_output.stdout | json_query('Devices[*].DevicePath') }}"
$ ansible-playbook test.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] ****************************************************************************************************************************************************************************************************************************
TASK [debug] ********************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"nvme_output.stdout": {
"Devices": [
{
"DevicePath": "/dev/nvme0n1",
"Firmware": "1.0",
"Index": 0,
"MaximumLBA": 33554432,
"ModelNumber": "Amazon Elastic Block Store",
"PhysicalSize": 17179869184,
"ProductName": "Non-Volatile memory controller: Vendor 0x1d0f Device 0x8061",
"SectorSize": 512,
"SerialNumber": "vol0e6af89fd1991cwtf",
"UsedBytes": 0
},
{
"DevicePath": "/dev/nvme1n1",
"Firmware": "1.0",
"Index": 1,
"MaximumLBA": 104857600,
"ModelNumber": "Amazon Elastic Block Store",
"PhysicalSize": 53687091200,
"ProductName": "Non-Volatile memory controller: Vendor 0x1d0f Device 0x8061",
"SectorSize": 512,
"SerialNumber": "vol0885625da4a60awtf",
"UsedBytes": 0
}
]
}
}
TASK [debug] ********************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"/dev/nvme0n1",
"/dev/nvme1n1"
]
}
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment