racke
(Stefan Hornburg)
April 3, 2019, 2:29pm
2
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
Hello Kunalsing,
please try pulp.stdout instead.
Regards
Racke
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
This should be
var: pulp.stdout
-R.Rao
Thank You sebastian. Now i am able to print stdout using
pulp.results.0.stdout
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’’’
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?
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
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?
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:
This issue is resolved now.
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 .