这与我尝试过的以下链接问题以及来自larsks的答案直接相关,但它不起作用:“如何循环遍历库存并在 ansible 中分配值”
我试图做同样的事情,并且我测试了重命名由 Ansible 控制的 2 个 VM,但是当我尝试运行 Playbook ( ansible-playbook -i hosts test_iterate_win.yml -vvv) 时出现类似下一个的错误,我会说它实际上是按名称 ' System.Object[]' 代替例如,wCloud2:
failed: [oldVM2] (item=[u'oldVM2', u'wCloud2']) => {
"ansible_loop_var": "item",
"changed": false,
"item": [
"oldVM2",
"wCloud2"
],
"msg": "Failed to rename computer to 'System.Object[]': Skip computer 'oldVM2' with new name 'System.Object[]' because the new name is not valid. The new computer name entered is not properly formatted. Standard names may contain letters (a-z, A-Z), numbers (0-9), and hyphens (-), but no spaces or periods (.). The name may not consist entirely of digits, and may not be longer than 63 characters.",
"old_name": "oldVM2",
"reboot_required": false
}
在我的库存文件中:
[windows]
oldVM1 ansible_host=192.168.122.6
oldVM2 ansible_host=192.168.122.139
我的剧本:
---
- hosts: windows
gather_facts: false
vars:
hostnames:
- wCloud1
- wCloud2
tasks:
- name: change hostname
win_hostname:
name: "{{ item }}"
loop: "{{ groups.windows|zip(hostnames)|list }}"
我做错了什么?