Score:0

Ansible: ERROR! 'shell' is not a valid attribute for a Play

mz flag
---
 - name: Extract PS output.
   shell: "ps -ef | grep pmon"
   register: pmon

 - name: Display PS output.
   debug:
     msg:
      - "{{ pmon.stdout_lines }}"

Error:

ERROR! 'shell' is not a valid attribute for a Play

The error appears to be in '/root/ansible_code/roles/sample_exercise/tasks/extractPS.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
 - name: Extract PS output.
   ^ here

Please advise on this error.

Command I am running:

[root@ansiblehost tasks]# pwd
/root/ansible_code/roles/sample_exercise/tasks
[root@ansiblehost tasks]# ansible-playbook -i /root/ansible_code/inventory.ini  /root/ansible_code/roles/sample_exercise/tasks/extractPS.yml --syntax-check
Score:0
ca flag

It is just a syntax error. It will not happen with a minimal example like

---
- hosts: localhost
  become: false
  gather_facts: false

  tasks:

  - name: Extract PS output.
    shell: 
      cmd: "ps -ef | grep pmon"
    register: pmon

  - name: Display PS output.
    debug:
      msg: "{{ pmon.stdout_lines }}"

You may take advantage from

Further Documentation

Learner avatar
mz flag
Hi @U880D Thank you very much! It works.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.