Ansible:错误!“shell”不是 Play 的有效属性

Ansible:错误!“shell”不是 Play 的有效属性
---
 - name: Extract PS output.
   shell: "ps -ef | grep pmon"
   register: pmon

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

错误:

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

请就此错误提供意见。

我正在运行的命令:

[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

这只是一个语法错误。在如下这个最小示例中不会发生这种情况

---
- 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 }}"

您可以利用

更多文档

相关内容