【发布时间】:2022-10-09 03:02:03
【问题描述】:
希望有人可以提供帮助。我只是在 Ansible 的世界中找到自己的脚,并尝试创建一个脚本来检查服务是否正在运行,如果它没有启动则启动它。这就是我到目前为止所拥有的。我不确定是否正确。
---
- hosts: all
tasks:
- name: Domain controller checks
block:
- name: Check Active Directory Domain Services are running
become_method: runas
win_service:
name: "{{ item }}"
start_mode: auto
state: started
loop:
- NTDS
- ADWS
- Dfs
- DFSR
- DNS
- Kdc
tasks:
- name: Restart failed services if needed
failure_actions:
- type: restart
delay_ms: 5000
通过 rundeck 运行此脚本时,出现以下错误:
[WARNING]: While constructing a mapping from<br />
<br />/etc/ansible/scripts/Service_ChecksV2.yml, line 2, column 5, found a duplicate
dict key (tasks). Using last defined value only.<br />
<br />ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'><br />
<br />The error appears to be in '/etc/ansible/scripts/Service_ChecksV2.yml': line 20, column 13, but may
be elsewhere in the file depending on the exact syntax problem.<br />
<br />The offending line appears to be:
<br />tasks:
- name: Restart failed services if needed
^ here
Failed: AnsibleNonZero: ERROR: Ansible execution returned with non zero code.<br />
【问题讨论】:
-
请注意,根据错误信息:“
found a duplicate dict key (tasks). Using last defined value only",有一个(某种)错字。至少需要删除第二次出现的剧本关键字tasks。 -
这不是一本有效的剧本,你有一些看起来像是使用不存在模块的任务定义。请查看
win_servicedocumentation 和该页面上的示例。我怀疑您要写的是this,但我无法确定,因为您的示例代码中存在太多问题。