how to access debug stdout variable

47 views
Skip to first unread message

Kunalsing Thakur

unread,
Apr 3, 2019, 10:22:32 AM4/3/19
to Ansible Project
playbook:-
task:-
- name: Deploying PCC-test
  hosts: pulp
  gather_facts: true
  vars_files:
    - /etc/ansible/inventories/group_vars/common.yaml
  vars:
    - rpmsearch: true
    - rpmname:
        - mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch
  serial: 1
  any_errors_fatal: true
  roles:
    - role: mobi_ansible_role_pulp

Pulp.yaml:-

---
- name: Logging into pulp
  shell: pulp-admin login -u admin -p admin
- name: searching the rpm into pulp repo
  shell: pulp-admin rpm repo content rpm --repo-id=mobi-snapshots --match 'filename={{ item }}'
  with_items: "{{ rpmname | default([]) }}"
  register: pulp
  when: rpmsearch is defined
- debug:
    var: pulp.results.stdout


Playbook output:-
PLAYBOOK: pulp.yaml **********************************************************************************************
1 plays in pulp.yaml
 [WARNING]: Found variable using reserved name: remote_user


PLAY [Deploying PCC-test] ****************************************************************************************

TASK [Gathering Facts] *******************************************************************************************
task path: /etc/ansible/playbooks/paytv/pulp.yaml:2
Wednesday 03 April 2019  14:18:45 +0000 (0:00:00.136)       0:00:00.136 *******
ok: [node]
META: ran handlers

TASK [mobi_ansible_role_pulp : include_tasks] ********************************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/main.yml:12
Wednesday 03 April 2019  14:18:49 +0000 (0:00:03.725)       0:00:03.862 *******
included: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml for inplp01p2.infra.smf1.mobitv

TASK [mobi_ansible_role_pulp : Logging into pulp] ****************************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:2
Wednesday 03 April 2019  14:18:49 +0000 (0:00:00.409)       0:00:04.271 *******
changed: [node] => changed=true
  cmd: pulp-admin login -u admin -p admin
  delta: '0:00:01.010085'
  end: '2019-04-03 14:18:51.477441'
  rc: 0
  start: '2019-04-03 14:18:50.467356'
  stderr: ''
  stderr_lines: []
  stdout: |-
    [0m[92mSuccessfully logged in. Session certificate will expire at Apr 10 14:18:51 2019
    GMT.[0m
  stdout_lines: <omitted>

TASK [mobi_ansible_role_pulp : searching the rpm into pulp repo] *************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:4
Wednesday 03 April 2019  14:18:51 +0000 (0:00:01.985)       0:00:06.256 *******
changed: [node] => (item=mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch) => changed=true
  cmd: pulp-admin rpm repo content rpm --repo-id=mobi-snapshots --match 'filename=mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch'
  delta: '0:00:01.417179'
  end: '2019-04-03 14:18:53.720125'
  item: mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch
  rc: 0
  start: '2019-04-03 14:18:52.302946'
  stderr: ''
  stderr_lines: []
  stdout: |-
    [0mArch:         noarch
    Buildhost:    3c33318f8330
    Checksum:     33816f5a2680403526591148da282e680655ad354fe23f80cc100824dcc1b4f1
    Checksumtype: sha256
    Description:  Mobi Auth Manager
    Epoch:        0
    Filename:     mobi-auth-manager-5.42.0-201903291228.ed4d6a0.noarch.rpm
    License:      MobiTV, Inc.
    Name:         mobi-auth-manager
    Provides:     mobi-auth-manager = 5.42.0-201903291228.ed4d6a0-0,
                  osgi(ch.qos.logback.classic) = 1.1.2-0, osgi(ch.qos.logback.core)
                  = 1.1.2-0, osgi(com.google.guava) = 14.0.1-0,
                  osgi(com.sun.jersey.client) = 1.17.0-0,
                  osgi(com.sun.jersey.contribs.jersey-apache-client) = 1.17.0-0,
                  osgi(com.sun.jersey.contribs.jersey-apache-client4) = 1.17.1-0,
                  osgi(com.sun.jersey.contribs.jersey-spring) = 1.17.0-0,
                  osgi(com.sun.jersey.core) = 1.17.0-0,
                  osgi(com.sun.jersey.jersey-server) = 1.17.0-0,
                  osgi(com.sun.jersey.json) = 1.17.0-0, osgi(com.sun.jersey.servlet)
                  = 1.17.0-0, osgi(com.sun.xml.bind) = 2.2.3-0, osgi(curator-client)
                  = 2.2.0-0, osgi(curator-framework) = 2.2.0-0,
                  osgi(curator-recipes) = 2.2.0-0, osgi(curator-x-discovery) =
                  2.2.0-0, osgi(jackson-core-asl) = 1.9.12-0, osgi(jackson-jaxrs) =
                  1.9.9-0, osgi(jackson-mapper-asl) = 1.9.9-0, osgi(jackson-xc) =
                  1.9.9-0, osgi(javax.ws.rs.jsr311-api) = 1.1.1-0, osgi(jaxb-api) =
                  2.2.2-0, osgi(jcl.over.slf4j) = 1.7.7-0, osgi(log4j.over.slf4j) =
                  1.7.7-0, osgi(org.apache.commons.codec) = 1.10.0-0,
                  osgi(org.apache.commons.collections) = 3.2.1-0,
                  osgi(org.apache.commons.io) = 2.4.0-0,
                  osgi(org.apache.commons.lang) = 2.6-0,
                  osgi(org.apache.commons.net) = 2.2-0,
                  osgi(org.apache.hadoop.zookeeper) = 3.4.5-0,
                  osgi(org.codehaus.jettison.jettison) = 1.1-0,
                  osgi(org.jboss.netty) = 3.2.3-0,
                  osgi(org.mortbay.jetty.servlet-api-2.5) = 2.5-0, osgi(slf4j.api) =
                  1.7.7-0, osgi(stax2-api) = 3.1.4-0, osgi(woodstox-core-asl) =
                  4.4.1-0
    Release:      201903291228.ed4d6a0
    Requires:     mobi-tomcat-config-8080 >= 8.0.17-0
    Version:      5.42.0
  stdout_lines: <omitted>

TASK [mobi_ansible_role_pulp : debug] ****************************************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:9
Wednesday 03 April 2019  14:18:53 +0000 (0:00:02.239)       0:00:08.496 *******
ok: [node] =>
  pulp.results.stdout: 'VARIABLE IS NOT DEFINED!: ''list object'' has no attribute ''stdout'''

Stefan Hornburg (Racke)

unread,
Apr 3, 2019, 10:29:52 AM4/3/19
to ansible...@googlegroups.com
Hello Kunalsing,

please try pulp.stdout instead.

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4f149a07-bf0a-4a5e-a1c2-6d40ce6fe993%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/4f149a07-bf0a-4a5e-a1c2-6d40ce6fe993%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Raghavendra Rao

unread,
Apr 3, 2019, 10:31:42 AM4/3/19
to ansible...@googlegroups.com
This should be
     var: pulp.stdout

-R.Rao

Sebastian Meyer

unread,
Apr 3, 2019, 10:31:59 AM4/3/19
to ansible...@googlegroups.com, Kunalsing Thakur
On 03.04.19 16:22, Kunalsing Thakur wrote:
> ---
> - name: Logging into pulp
> shell: pulp-admin login -u admin -p admin
> - name: searching the rpm into pulp repo
> shell: pulp-admin rpm repo content rpm --repo-id=mobi-snapshots --match
> 'filename={{ item }}'
> with_items: "{{ rpmname | default([]) }}"
> register: pulp
> when: rpmsearch is defined

You are using register with a loop. That means pulp.results is a list
and there's an element for each item in that list.

You can access the stdout for the first item with pulp.results.0.stdout

Sebastian
--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

kunalsing thakur

unread,
Apr 3, 2019, 10:38:06 AM4/3/19
to ansible...@googlegroups.com, Kunalsing Thakur
Thank You sebastian. Now i am able to print stdout using
pulp.results.0.stdout

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d0544de0-7767-8996-9d83-c037b4307869%40b1-systems.de.

For more options, visit https://groups.google.com/d/optout.


--

Kunalsing Thakur

unread,
Apr 3, 2019, 10:44:31 AM4/3/19
to Ansible Project
Hi sebastian,
when i try to fail the task with this below condition i get the error in task

failed_when: pulp.results.0.stdout == "\e[0m"

TASK [mobi_ansible_role_pulp : searching the rpm into pulp repo] *************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:4
Wednesday 03 April 2019  14:40:58 +0000 (0:00:01.856)       0:00:06.231 *******
fatal: [inplp01p2.infra.smf1.mobitv]: FAILED! =>
  msg: 'The conditional check ''pulp.results.0.stdout == "\e[0m"'' failed. The error was: error while evaluating conditional (pulp.results.0.stdout == "\e[0m"): ''dict object'' has no attribute ''results'''

Kunalsing Thakur

unread,
Apr 3, 2019, 10:47:51 AM4/3/19
to Ansible Project
when i print the pulp.results.0.stdout it will give me following output:-
TASK [mobi_ansible_role_pulp : debug] ****************************************************************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:9
Wednesday 03 April 2019  14:46:40 +0000 (0:00:02.206)       0:00:09.036 *******
ok: [inplp01p2.infra.smf1.mobitv] =>
  pulp.results.0.stdout: "\e[0m"
which is blank so i want to failed this task?

Sebastian Meyer

unread,
Apr 3, 2019, 10:48:02 AM4/3/19
to ansible...@googlegroups.com, Kunalsing Thakur
On 03.04.19 16:44, Kunalsing Thakur wrote:
> Hi sebastian,
> when i try to fail the task with this below condition i get the error in
> task
>
> *failed_when: pulp.results.0.stdout == "\e[0m"*
>
> TASK [mobi_ansible_role_pulp : searching the rpm into pulp repo]
> *************************************************
> task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:4
> Wednesday 03 April 2019 14:40:58 +0000 (0:00:01.856) 0:00:06.231
> *******
> fatal: [inplp01p2.infra.smf1.mobitv]: FAILED! =>
> msg: 'The conditional check ''pulp.results.0.stdout == "\e[0m"'' failed.
> The error was: error while evaluating conditional (pulp.results.0.stdout ==
> "\e[0m"): ''dict object'' has no attribute ''results'''

While you are in the loop you should be able to use just pulp.stdout,
only afterwards the results are merged.

Sebastian

>
>
> On Wednesday, April 3, 2019 at 8:01:59 PM UTC+5:30, Sebastian Meyer wrote:
>>
>> On 03.04.19 16:22, Kunalsing Thakur wrote:
>>> ---
>>> - name: Logging into pulp
>>> shell: pulp-admin login -u admin -p admin
>>> - name: searching the rpm into pulp repo
>>> shell: pulp-admin rpm repo content rpm --repo-id=mobi-snapshots
>> --match
>>> 'filename={{ item }}'
>>> with_items: "{{ rpmname | default([]) }}"
>>> register: pulp
>>> when: rpmsearch is defined
>>
>> You are using register with a loop. That means pulp.results is a list
>> and there's an element for each item in that list.
>>
>> You can access the stdout for the first item with pulp.results.0.stdout
>>
>> Sebastian
>> --
>> Sebastian Meyer
>> Linux Consultant & Trainer
>> Mail: me...@b1-systems.de <javascript:>

Kunalsing Thakur

unread,
Apr 3, 2019, 12:02:49 PM4/3/19
to Ansible Project
Hi sebastian,
pulp.results.0.stdout give me output "\e[0m"

But when I try to access in failed_when condition
It is giving me below error.
fatal: [node]: FAILED! =>

  msg: 'The conditional check ''pulp.results.0.stdout == "\e[0m"'' failed. The error was: error while evaluating conditional (pulp.results.0.stdout == "\e[0m"): ''dict object'' has no attribute ''results'''

Looks like in faiked_when condition it needs dictionary?




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Kunalsing Thakur

unread,
Apr 6, 2019, 6:09:30 AM4/6/19
to Ansible Project
I was able to successfully do this task by following the instructions.
Thanks for matt to give some logic.

- name: searching the rpm into {{ reponame }} repo
  shell: pulp-admin rpm repo content rpm --repo-id={{reponame}} --match 'filename={{ item }}'
  loop: "{{ rpmname | default([]) }}"
  register: pulp
  when: search is defined
  failed_when: pulp.stdout == "\u001b[0m"

Result:-
TASK [mobi_ansible_role_pulp : searching the rpm into infra] ******************************
task path: /etc/ansible/roles/mobi_ansible_role_pulp/tasks/pulp.yaml:5
Saturday 06 April 2019  10:07:15 +0000 (0:00:02.298)       0:00:02.709 ********
failed: [node] (item=GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86_64.rpm) => changed=true
  cmd: pulp-admin rpm repo content rpm --repo-id=mobi-infra.smf1.mobitv --match 'filename=GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86_64.rpm'
  delta: '0:00:00.781775'
  end: '2019-04-06 10:07:17.178794'
  failed_when_result: true
  item: GoIP-devel-1.6.11-201711302323.798cb6f.el7.centos.x86_64.rpm
  rc: 0
  start: '2019-04-06 10:07:16.397019'
  stderr: ''
  stderr_lines: []
  stdout: "\e[0m"
  stdout_lines: <omitted>


This issue is resolved now. :)

Melissa Liana

unread,
Apr 8, 2019, 1:27:15 AM4/8/19
to Ansible Project

Hi, 

Instead of stdout, I would suggest using stdout_lines. For multiline output this is much nicer, e.g.

- hosts: all
  tasks:
    - name: Run ls.sh and output "ls /"
      script: ls.sh
      register: out

    - debug: var=out.stdout_lines

gives

TASK: [debug var=out.stdout_lines] ******************************************** 
ok: [local] => {
    "var": {
        "out.stdout_lines": [
            "total 61", 
            "lrwxrwxrwx   1 root root     7 Feb 15  2015 bin -> usr/bin", 
            "drwxr-xr-x   6 root root  1024 Aug 24 22:08 boot", 
            "drwxr-xr-x  22 root root  3580 Sep  8 18:41 dev",  
            [...] 
            "drwxr-xr-x   9 root root  4096 Aug 25 19:14 usr", 
            "drwxr-xr-x  13 root root  4096 Feb 25  2015 var"
        ]
    }
}

Regarding real-time output for debugging purposes, there is a closed bug reporthttps://github.com/ansible/ansible/issues/3887#issuecomment-54672569 discussing the reasons why this is not possible and will not be implemented.


Thanks and regards,

Liana melissa,

Automation developer.

Reply all
Reply to author
Forward
0 new messages