Reputation: 365
I am facing error while executing below ansible playbook. I don't know what I am missing, in with_items
Trying to retrieve disk details using gather_subset
module and partition each disk that is available in the file system by looping into the var
Error Message:
fatal: [localhost]: FAILED! => {"msg": "'dict object' has no attribute 'list'"}
Playbook:
---
- hosts: localhost
become: true
gather_facts: false
tasks:
- name: Collect Disk Information
setup:
gather_subset:
- hardware
- name: Print disks Details
debug:
var: hostvars[inventory_hostname].ansible_devices.keys()| list
- name: Create Partition
parted:
device: "{{ item }}"
number: 1
part_type: 'primary'
state: present
with_items: "{{ disks.list[0] }}"
Print disk details task is printing below
TASK [Print disks Details] ***************************************************************************************************
ok: [localhost] => {
"hostvars[inventory_hostname].ansible_devices.keys()| list": [
"xvdf",
"xvdb",
"xvdc",
"xvda"
]
}
Upvotes: 0
Views: 2329
Reputation: 41
I see an issue in your example, you are refering to var disks, but I cannot see this is set anywhere in your example.
You should replace your last syntax:
- name: Create Partition
parted:
device: "{{ item }}"
number: 1
part_type: 'primary'
state: present
with_items: "{{hostvars[inventory_hostname].ansible_devices.keys()}}"
Upvotes: 1