gpt4 book ai didi

Ansible win_update 问题 - 加载任务时遇到格式错误的 block

转载 作者:行者123 更新时间:2023-12-04 04:19:33 25 4
gpt4 key购买 nike

我尝试使用以下任一 Windows 更新剧本,但在执行时遇到了同样的错误。

---
- name: Install all windows security and critical updates and wait 10 mins
hosts: windowsservers
tasks:
win_updates:
category_names:
- CriticalUpdates
- SecurityUpdates
blacklist:
- Windows Malicious Software Removal Tool for Windows
reboot: yes
reboot_timeout: 600

---
- name: Install all windows security and critical updates and wait 10 mins
hosts: windowsservers
tasks:
win_updates:
category_names:
- CriticalUpdates
- SecurityUpdates
blacklist:
- Windows Malicious Software Removal Tool for Windows
reboot: yes
reboot_timeout: 600

以下是我在尝试执行上述任一剧本时收到的错误消息。我一直在到处搜索,但找不到任何相关问题。 Ansible 专家可以帮忙吗?

ERROR! A malformed block was encountered while loading tasks: {u'win_updates': {u'blacklist': [u'Windows Malicious Software Removal Tool for Windows'], u'reboot_timeout': 600, u'category_names': [u'CriticalUpdates', u'SecurityUpdates'], u'reboot': True}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

The error appears to be in '/home/username/ansible/playbooks/windowsupdate/install_windows_secupdate.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Install all windows security and critical updates and wait 10 mins
^ here

以下是我用作引用文章的内容。

https://docs.ansible.com/ansible/latest/modules/win_updates_module.html
https://www.ansible.com/blog/windows-updates-and-ansible

最佳答案

正如您的错误消息所清楚解释的那样

ERROR! A malformed block was encountered while loading tasks: {u'win_updates': {u'blacklist': [u'Windows Malicious Software Removal Tool for Windows'], u'reboot_timeout': 600, u'category_names': [u'CriticalUpdates', u'SecurityUpdates'], u'reboot': True}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

ansible-playbook 期望在您的剧本中的 tasks 参数中有一个列表(您的剧本中通常有多个任务)。

此错误会阻止您的任何一个剧本版本进一步实际执行。

关于您的第二个 playbook 版本(除了列表/哈希格式错误),您的 reboot* 参数没有正确缩进:它们是 win_updates 模块选项,而不是任务级别选项(例如 loopregisterwhen 等)。第一个版本是好的。

这是您的剧本的固定版本(仅语法,未测试),其中:

  • 我将任务转换为列表
  • 我为您的任务添加了一个名称作为一般良好做法
---
- name: Install all windows security and critical updates and wait 10 mins
hosts: windowsservers
tasks:
- name: Install updates
win_updates:
category_names:
- CriticalUpdates
- SecurityUpdates
blacklist:
- Windows Malicious Software Removal Tool for Windows
reboot: yes
reboot_timeout: 600

验证语法:

使用上面的剧本:

$ ansible-playbook playbook_bad.yml --syntax-check
ERROR! A malformed block was encountered while loading tasks: {'name': 'Install updates', 'win_updates': {'category_names': ['CriticalUpdates', 'SecurityUpdates'], 'blacklist': ['Windows Malicious Software Removal Tool for Windows'], 'reboot': True, 'reboot_timeout': 600}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

The error appears to be in '/tmp/playbook_bad.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Install all windows security and critical updates and wait 10 mins
^ here

使用建议的修复:

$ ansible-playbook playbook.yml --syntax-check
[WARNING]: Could not match supplied host pattern, ignoring: windowsservers


playbook: playbook.yml

警告只是因为我的库存中没有您的机器/组。

关于Ansible win_update 问题 - 加载任务时遇到格式错误的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59725230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com