I am trying to isolate the output of the ansible playbook however it says "output.stdout": "VARIABLE IS NOT DEFINED!"

My playbook code is: --- - hosts: localhost tasks: - name: Register variable shell: "echo {{ item }}" loop: - "one" - "two" register: output - debug: var: output.stdout

Interestingly , the debug output works fine if i dont isolate it using stdout key.

TASK [Register variable] ***********************************************************************************************************************************************
changed: [localhost] => (item=one)
changed: [localhost] => (item=two)

TASK [debug] ***********************************************************************************************************************************************************
ok: [localhost] => {
    "output": {
        "changed": true,
        "msg": "All items completed",
        "results": [
                "ansible_loop_var": "item",
                "changed": true,
                "cmd": "echo one",
                "delta": "0:00:00.002986",
                "end": "2020-01-24 00:20:57.226744",
                "failed": false,
                "invocation": {
                    "module_args": {
                        "_raw_params": "echo one",
                        "_uses_shell": true,
                        "argv": null,
                        "chdir": null,
                        "creates": null,

What am i doing wrong ?



When you use register with a loop, the data structure placed in the variable will contain a results attribute that is a list of all responses from the module


|improve this answer|||||

An easier way would be to loop into a separate .yml file (via include), which will perform a gentle operation + output. For example:


- name: RUN start.yml
  include: start.yml
    app: "{{ item.name }}"
  static: false
  with_items: "{{ list_items }}"

start.yml in same role:

- name: "Run {{ app }}"
  command: './runapp.sh {{ app }}'
  register: start_app_register
  no_log: True

- debug:
    msg: '{{ start_app_register.stdout }}'
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.