【问题标题】:Error 'dict object' has no attribute 'list' while executing ansible playbook执行 ansible playbook 时出现错误“dict object”没有属性“list”
【发布时间】:2021-05-03 18:10:17
【问题描述】:

我在执行下面的 ansible playbook 时遇到错误。我不知道我错过了什么,with_items

尝试使用gather_subset 模块检索磁盘详细信息,并通过循环进入var 对文件系统中可用的每个磁盘进行分区 错误信息:

fatal: [localhost]: FAILED! => {"msg": "'dict object' has no attribute 'list'"}

剧本:

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

打印磁盘详细信息下面正在打印任务

TASK [Print disks Details] ***************************************************************************************************
ok: [localhost] => {
    "hostvars[inventory_hostname].ansible_devices.keys()| list": [
        "xvdf",
        "xvdb",
        "xvdc",
        "xvda"
    ]
}

【问题讨论】:

    标签: ansible


    【解决方案1】:

    我在您的示例中看到了一个问题,您指的是 var disks,但我看不到您的示例中的任何地方都设置了这个。

    你应该替换你最后的语法:

    - name: Create Partition
      parted:
        device: "{{ item }}"
        number: 1
        part_type: 'primary'
        state: present
    with_items: "{{hostvars[inventory_hostname].ansible_devices.keys()}}"
      
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      相关资源
      最近更新 更多