循环中的寄存器未给出预期输出-Ansible

循环中的寄存器未给出预期输出-Ansible,ansible,Ansible,我正在写一本剧本,它给了我循环中进程列表的状态,但输出并不是预期的结果 我使用的是ansible 2.7.1 --- - hosts: test_group gather_facts: false tasks: - name: checking status shell: /etc/init.d/{{ item }} status register: output loop: - gdac - scac - name : pr

我正在写一本剧本,它给了我循环中进程列表的状态,但输出并不是预期的结果

我使用的是ansible 2.7.1

---
- hosts: test_group
  gather_facts: false
  tasks:
  - name: checking status
    shell: /etc/init.d/{{ item }} status
    register: output
    loop:
       - gdac
       - scac

  - name : print status
    debug:
      msg: "{{ item.stdout }}"
      loop: "{{ output.results }}"
预期的输出类似(这给了我来自注册变量的stdout或stdout_行)

"msg":"Poller is Running\nSpooler is Running"
"msg": scac.db1: 3 of 3 running ( 7067 7060 7040 )\nayld.db1: 1 of 1 running ( 7114 )\nscac.db2: 3 of 3 running ( 7227 7216 7203 )\nayld.db2: 0 of 1 running
但是我犯了错误

fatal: [test01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined
``

在第二个任务中,您将
循环
声明为
调试
模块的一个选项

它应该是任务的选项,而不是模块的选项。由于任务没有
循环
声明,
未定义

您只需修复缩进:

- name : print status
  debug:
    msg: "{{ item.stdout }}"
  loop: "{{ output.results }}"

非常感谢。这很有效。我知道了缩进的重要性