0
---
 - 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

1 Answer 1

1

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .