0

I am writing a playbook that gives me the status of list of processes in loop but the output is not coming a desired

I am using 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 }}"

expecting output like (which given me the stdout or stdout_lines from the registered variable.

"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

but am getting error

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

1 Answer 1

1

In your second task, you declared loop as an option of the debug module.

It should be an option of the task, not of the module. Since there is no loop declaration for the task, item is undefined.

You just have to fix your indentation:

- name : print status
  debug:
    msg: "{{ item.stdout }}"
  loop: "{{ output.results }}"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. That worked. Got to know the importance of indentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.