Is there a way to extract stdout variables from Ansible?
Here is my script:
-
hosts: myhost
sudo: yes
tasks: -
name: output bash
command: rpm -q bash
register: result -
debug: msg=“{{ result.stderr }}”
Here is the output:
[root@ansi playbooks]$ ansible-playbook which_bash.yml
PLAY [myhost] ***************************************************
TASK [setup] *******************************************************************
ok: [myhost]
TASK [which bash RPM] **********************************************************
changed: [myhost]
[WARNING]: Consider using yum module rather than running rpm
TASK [debug] *******************************************************************
ok: [myhost] => {
“bash_version”: {
“changed”: true,
“cmd”: [
“rpm”,
“-q”,
“bash”
],
“delta”: “0:00:00.045905”,
“end”: “2016-06-11 18:22:07.782431”,
“rc”: 0,
“start”: “2016-06-11 18:22:07.736526”,
“stderr”: “”,
“stdout”: “bash-4.2.46-12.el7.x86_64”,
“stdout_lines”: [
“bash-4.2.46-12.el7.x86_64”
],
“warnings”: [
“Consider using yum module rather than running rpm”
]
}
}
PLAY RECAP *********************************************************************
myhost : ok=3 changed=1 unreachable=0 failed=0
The output works great. However I’m looking or a way to only extract the stdout from that output. I want nothing but stdout. How can I do that?
thanks in advance.