0

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"
    ]
}

1 Answer 1

1

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()}}"
  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.