Ansible - 'block'不是 Play 的有效属性



我正试图找出如何解决错误消息:Error!'块"不是播放的有效属性

我该如何做到这一点?我正在尝试使用";块";条件,但不起作用。我不知道该搜索什么了。

代码:

---
- name: Get diagnostic info block
block:
- name: Get top process diagnostic info
script: library/diag_top_processes.ps1
failed_when: false
changed_when: false
register: diag_top_proc_out
- name: Get memory and pagefile usage diagnostic info
script: library/diag_memory_and_pagefile.ps1
failed_when: false
changed_when: false
register: diag_mem_page_out
- name: Get CPU info
script: library/diag_cpu_info.ps1
failed_when: false
changed_when: false
register: diag_cpu_info_out
- name: Init diag message
set_fact:
diag_msg: "Diagnostic information:"
proc_info:
"{{ diag_top_proc_out.stdout|regex_replace('rn|n|r', '') }}"
cpu_info: "{{ diag_cpu_info_out.stdout_lines | join(' ') }}"
- name: Add top process info
set_fact:
diag_msg: "{{ [diag_msg, proc_info] | join(' ') }}"
- name: Add memory info
set_fact:
diag_msg:
"{{ [diag_msg, diag_mem_page_out.stdout_lines[0]] | join(' ') }}"
- name: Add CPU info
set_fact:
diag_msg:
"{{ [diag_msg, cpu_info] | join(' ') }}"
rescue:
- name: Diag info collection failed, setup variable
set_fact:
diag_failed: true

使用"块"播放时出错:

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! 'block' is not a valid attribute for a Play
The error appears to be in '/home/keith/Ansible/ansible-role-high-cpu-usage-win/tasks/get_diagnostic.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

- name: Get diagnostic info block
^ here

只有在进行时,此文件才正确

- include_tasks path/to/get_diagnostic.yml

正如lopez所说,它不能用ansible playbook命令行调用。

将播放重写为:

---
- name: Play
tasks:
- name: Get diagnostic info block
block:
- name: Get top process diagnostic info
script: library/diag_top_processes.ps1
failed_when: false
changed_when: false
register: diag_top_proc_out
....
rescue:
- name: Another tasks
....

相关内容

最新更新