Ansible "block" error

233 views
Skip to first unread message

Keith Mills

unread,
Apr 13, 2021, 11:04:14 AM4/13/21
to Ansible Project
How do I troubleshoot the Ansible Error “block is not a valid attribute for a Play”? Or, is there a better attribute to use here?

Ansible Version:

ansible 2.9.18
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/keith/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

Playbook:

---

- 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('\r\n|\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

Error:

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

Stefan Hornburg (Racke)

unread,
Apr 13, 2021, 12:23:20 PM4/13/21
to ansible...@googlegroups.com
On 4/13/21 5:04 PM, Keith Mills wrote:
> How do I troubleshoot the Ansible Error “block is not a valid attribute for a Play”? Or, is there a better attribute to
> use here?

Your code in your playbook should be inside "tasks:".

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d6605a8d-68c8-4b2c-9a6e-9fe62ec1fd45n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/d6605a8d-68c8-4b2c-9a6e-9fe62ec1fd45n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages