Ansible: how to get output to display

I have the next play, Playbook with an exit

There are currently no errors and it is working fine. However, it does not display console output. I came across this with other game books and went around it by adding the following play to the textbook:

-debug: var=output.stdout_lines

and it outputs the result. However, I tried to do the same in the above, and it says that the variable was undefined (the code is not shown because it did not work).

Does anyone know how best to get output to print to the console without using -debug? Any important links would be appreciated.

+4
source share
1 answer

, , . , . register, .

. , , :

---
- hosts: localhost
  tasks:
    - shell: ls
      register: shell_result

    - debug:
        var: shell_result.stdout_lines

register shell_result, debug .

:

PLAY [localhost] ***************************************************************

TASK [command] *****************************************************************
changed: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] => {
    "shell_result.stdout_lines": [
        "play.yml"
    ]
}

. stdout_lines , .

, , , , stdout stdout_lines, msg . , - , .

. : -v, -vvv -vvvv. , playbook (-vvv) :

PLAY [localhost] ***************************************************************

TASK [command] *****************************************************************
(...)
changed: [localhost] => {
    "changed": true,
    "cmd": "ls",
    "delta": "0:00:00.007621",
    "end": "2017-02-17 23:04:41.912570",
    "invocation": {
        "module_args": {
            "_raw_params": "ls",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "warn": true
        },
        "module_name": "command"
    },
    "rc": 0,
    "start": "2017-02-17 23:04:41.904949",
    "stderr": "",
    "stdout": "play.retry\nplay.yml",
    "stdout_lines": [
        "play.retry",
        "play.yml"
    ],
    "warnings": []
}

, . , stdout_lines , , .

jenkins_script, , , output, :

tasks:
  - jenkins_script:
      script: (...)
    register: jenkins_result

  - debug:
      var: jenkins_result.output
+11

Source: https://habr.com/ru/post/1670100/


All Articles