错误';dict对象';没有属性';列表';在执行ansible剧本时
我在执行ansible剧本时遇到错误。我不知道我在错误';dict对象';没有属性';列表';在执行ansible剧本时,ansible,Ansible,我在执行ansible剧本时遇到错误。我不知道我在和\u项中缺少了什么 尝试使用gather\u subset模块检索磁盘详细信息,并通过循环到var 错误消息: fatal: [localhost]: FAILED! => {"msg": "'dict object' has no attribute 'list'"} --- - hosts: localhost become: true gather_facts: false t
和\u项中缺少了什么
尝试使用gather\u 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] }}"
剧本:
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"
]
}
我在您的示例中看到了一个问题,您引用的是var磁盘,但我看不到在您的示例中的任何地方设置了这个问题
您应该替换上一个语法:
- name: Create Partition
parted:
device: "{{ item }}"
number: 1
part_type: 'primary'
state: present
with_items: "{{hostvars[inventory_hostname].ansible_devices.keys()}}"