how can I take the results and pass it through dictionary in ansible - ansible

---
#test loop with_item
- hosts: all
become: yes
gather_facts: no
pre_tasks:
- name: delete /tmp/test.txt
file:
path: /tmp/test.txt
state: absent
tasks:
- name: set facts ad_users
set_fact:
ad_users: []
- name: set facts ad_users, need to populate ad_results <--------------------
set_fact:
ad_results: {}
- name: Recursively find /home
find:
paths: /home
file_type: directory
register: find_var
- name: Append string to list
set_fact:
ad_users: "{{ ad_users + [ item.path| basename ] }}"
loop: "{{ find_var.files }}"
- debug: var=ad_users
- name: Get full username from Active Directory
shell: "/bin/adquery user '{{ item }}'| awk -F: '{print $5}'"
register: ad_fullname
loop: "{{ ad_users }}"
- name: debug ad_fullname
debug:
var: ad_fullname.results
Here is the result of fullname.results from debug
TASK [debug ad_fullname] **************************************************************
ok: [centos-test] => {
"ad_fullname.results": [
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "apps",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/adquery user 'apps'| awk -F: '{print $5}'",
"delta": "0:00:00.022701",
"end": "2019-06-28 00:09:02.713134",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/bin/adquery user 'apps'| awk -F: '{print $5}'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "apps",
"rc": 0,
"start": "2019-06-28 00:09:02.690433",
"stderr": "apps is not a zone user",
"stderr_lines": [
"apps is not a zone user"
],
"stdout": "",
"stdout_lines": []
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "linuxtest",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/adquery user 'linuxtest'| awk -F: '{print $5}'",
"delta": "0:00:00.017644",
"end": "2019-06-28 00:09:02.841312",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/bin/adquery user 'linuxtest'| awk -F: '{print $5}'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "linuxtest",
"rc": 0,
"start": "2019-06-28 00:09:02.823668",
"stderr": "",
"stderr_lines": [],
"stdout": "linux test",
"stdout_lines": [
"linux test"
]
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "linuxtest2",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/adquery user 'linuxtest2'| awk -F: '{print $5}'",
"delta": "0:00:00.017439",
"end": "2019-06-28 00:09:02.966616",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/bin/adquery user 'linuxtest2'| awk -F: '{print $5}'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "linuxtest2",
"rc": 0,
"start": "2019-06-28 00:09:02.949177",
"stderr": "",
"stderr_lines": [],
"stdout": "linux test2",
"stdout_lines": [
"linux test2"
]
},
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "cngo",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/adquery user 'cngo'| awk -F: '{print $5}'",
"delta": "0:00:00.022745",
"end": "2019-06-28 00:09:03.097507",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/bin/adquery user 'cngo'| awk -F: '{print $5}'",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "cngo",
"rc": 0,
"start": "2019-06-28 00:09:03.074762",
"stderr": "cngo is not a zone user",
"stderr_lines": [
"cngo is not a zone user"
],
"stdout": "",
"stdout_lines": []
}
]
}
I need populate dictionary ad_results with
ad_fullname.results.item: ad_fullname.results.stdout
when ad_fullname.results.stdout is not define
the problem is
when I try to debug
I keep getting error
- name: debug ad_fullname
debug:
var: ad_fullname.results.item
I keep getting this error
"ad_fullname.results.item": "VARIABLE IS NOT DEFINED!"

As its name implies, and your example text shows, .results is a list and thus has no such property item; you are looking for:
- name: debug ad_fullname
debug:
msg: '{{ ad_fullname.results | map(attribute="item") | list }}'

Related

Ansible: loop our shell command(Linux user group search) result and display the groups

Ansible: loop our shell command(Linux user group search) result and display the groups
Task to check if group exist
- name: "Checking if group doesn't exist"
shell: "grep -i {{ item.group }} /etc/group"
register: presence
loop: "{{ UserAddList.add_users }}"
ignore_errors: true
no_log: true
Json input file:
UserAddList is a json file
{
"add_users": [
{
"name": "test1_123",
"group": "test1_123",
"additional_groups":
[
"test2",
"group1"
],
"password" : "test1_newcdsaf",
"sudo_entry": "ALL=(ALL) NOPASSWD: ALL",
"comment": "test1"
}
],
"delete_users": [
]
}
Task to display the groups doesn't exist
- name: The following groups does't' exist
debug:
msg:
"{{ item._ansible_item_label.group }}"
loop: "{{ presence.results }}"
output:
(item={
'_ansible_parsed': True,
'stderr_lines': [
],
u'changed': True,
u'stdout': u'',
'_ansible_item_result': True,
u'msg': u'non-zero return code',
u'delta': u'0:00:00.008175',
'stdout_lines': [
],
'_ansible_item_label': {
u'comment': u'test1',
u'password': u'test1_newcdsaf',
u'group': u'test1_123',
u'name': u'test1_123',
u'sudo_entry': u'ALL=(ALL) NOPASSWD: ALL',
u'additional_groups': [
u'test2',
u'group1'
]
},
u'end': u'2019-12-10 14:23:15.725676',
'_ansible_no_log': True,
'item': {
u'comment': u'test1',
u'password': u'test1_newcdsaf',
u'group': u'test1_123',
u'name': u'test1_123',
u'sudo_entry': u'ALL=(ALL) NOPASSWD: ALL',
u'additional_groups': [
u'test2',
u'group1'
]
},
u'cmd': u'grep -i test1_123 /etc/group',
u'failed': True,
u'stderr': u'',
u'rc': 1,
u'invocation': {
u'module_args': {
u'warn': True,
u'executable': None,
u'_uses_shell': True,
u'_raw_params': u'grep -i test1_123 /etc/group',
u'removes': None,
u'argv': None,
u'creates': None,
u'chdir': None,
u'stdin': None
}
},
u'start': u'2019-12-10 14:23:15.717501'
})=>{
"changed": false,
"item": {
"changed": true,
"cmd": "grep -i test1_123 /etc/group",
"delta": "0:00:00.008175",
"end": "2019-12-10 14:23:15.725676",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "grep -i test1_123 /etc/group",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": {
"additional_groups": [
"test2",
"group1"
],
"comment": "test1",
"group": "test1_123",
"name": "test1_123",
"password": "test1_newcdsaf",
"sudo_entry": "ALL=(ALL) NOPASSWD: ALL"
},
"msg": "non-zero return code",
"rc": 1,
"start": "2019-12-10 14:23:15.717501",
"stderr": "",
"stderr_lines": [
],
"stdout": "",
"stdout_lines": [
]
},
"msg": "test1_123"
}
I don't want to display the whole output, I just want to display the groups information.
The debug is printing all the input data as well.
Please any suggestions
The debug is printing all the input data as well.
It's actually not the debug: task that is printing your data, ansible is showing you what it is looping over. However, you are using loop: over the top-level presence.results list, and .results contains not only the output you care about, but also the invocation parameters, success or failure, and the actual returned data that you care about
There are two ways of fixing that problem: tell ansible that you only want it to show something smaller in the loop label, or change the loop: to actually only loop over the deleted users
In the first way, loop_control: will do that (it even cites your exact circumstance in the docs saying When looping over complex data structures, the console output of your task can be enormous. To limit the displayed output, use the label directive with loop_control):
- name: The following groups does't' exist
debug:
msg:
"{{ item._ansible_item_label.group }}"
loop: "{{ presence.results }}"
loop_control:
label: "{{ item.item.name }}"
In the second way, just select out the group you care about and msg: it:
- name: The following groups does't' exist
debug:
msg:
"{{ item }}"
loop: "{{ presence.results | map(attribute='item') | map(attribute='group') | list }}"

Ansible: Register and display results through iteration

My playbook is
---
- name: Running Checks on ACTIVATION VMs of ECM
hosts: activationvms
tasks:
- name: Checking File System status
shell: df -PTh
register: filesystem_check
- name: Display File System Statistics
debug:
msg: "{{ filesystem_check.stdout_lines }}"
- name: Check the status of list of services
shell: systemctl list-units|grep "{{ item }}"|awk '{ print $1,$2,$3,$4}'
with_items:
- zookeeper.service
- cassandra.service
register: service_status
- name: Display services status
debug:
msg: "{{ item.stdout }}"
with_items: "{{ service_status.results }}"
I want to shrink the results to only the msg line.
ok: [10.142.6.79] => (item={u'_ansible_parsed': True, u'changed': True, u'stdout': u'cassandra.service loaded active running', u'_ansible_no_log': False, u'stdout_lines': [u'cassandra.service loaded active running'], u'warnings': [], u'_ansible_item_result': True, u'start': u'2019-11-15 07:50:39.047456', u'delta': u'0:00:00.011821', u'cmd': u'systemctl list-units|grep "cassandra.service"|awk \'{ print $1,$2,$3,$4}\'', u'item': u'cassandra.service', u'rc': 0, u'invocation': {u'module_name': u'command', u'module_args': {u'warn': True, u'executable': None, u'_uses_shell': True, u'_raw_params': u'systemctl list-units|grep "cassandra.service"|awk \'{ print $1,$2,$3,$4}\'', u'removes': None, u'creates': None, u'chdir': None}}, u'end': u'2019-11-15 07:50:39.059277', u'stderr': u''}) => {
"item": {
"changed": true,
"cmd": "systemctl list-units|grep \"cassandra.service\"|awk '{ print $1,$2,$3,$4}'",
"delta": "0:00:00.011821",
"end": "2019-11-15 07:50:39.059277",
"invocation": {
"module_args": {
"_raw_params": "systemctl list-units|grep \"cassandra.service\"|awk '{ print $1,$2,$3,$4}'",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"item": "cassandra.service",
"rc": 0,
"start": "2019-11-15 07:50:39.047456",
"stderr": "",
"stdout": "cassandra.service loaded active running",
"stdout_lines": [
"cassandra.service loaded active running"
],
"warnings": []
},
"msg": "cassandra.service loaded active running"
}
ok: [10.142.6.72] => (item={u'_ansible_parsed': True, u'changed': True, u'stdout': u'cassandra.service loaded active running', u'_ansible_no_log': False, u'stdout_lines': [u'cassandra.service loaded active running'], u'warnings': [], u'_ansible_item_result': True, u'start': u'2019-11-15 07:50:39.429296', u'delta': u'0:00:00.011853', u'cmd': u'systemctl list-units|grep "cassandra.service"|awk \'{ print $1,$2,$3,$4}\'', u'item': u'cassandra.service', u'rc': 0, u'invocation': {u'module_name': u'command', u'module_args': {u'warn': True, u'executable': None, u'_uses_shell': True, u'_raw_params': u'systemctl list-units|grep "cassandra.service"|awk \'{ print $1,$2,$3,$4}\'', u'removes': None, u'creates': None, u'chdir': None}}, u'end': u'2019-11-15 07:50:39.441149', u'stderr': u''}) => {
"item": {
"changed": true,
"cmd": "systemctl list-units|grep \"cassandra.service\"|awk '{ print $1,$2,$3,$4}'",
"delta": "0:00:00.011853",
"end": "2019-11-15 07:50:39.441149",
"invocation": {
"module_args": {
"_raw_params": "systemctl list-units|grep \"cassandra.service\"|awk '{ print $1,$2,$3,$4}'",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"item": "cassandra.service",
"rc": 0,
"start": "2019-11-15 07:50:39.429296",
"stderr": "",
"stdout": "cassandra.service loaded active running",
"stdout_lines": [
"cassandra.service loaded active running"
],
"warnings": []
},
"msg": "cassandra.service loaded active running"
You need to use loop control tool. Rewrite your last play like this
- name: Display services status
debug:
msg: "{{ item.stdout }}"
with_items: "{{ service_status.results }}"
loop_control:
label: "{{ item.item }}"
That will limit that output to just the thing that was iterated into your prior command so you can tell which part of the loop you are currently in.

How do i access the results array to get a specific value in the objects returned

I am having trouble accessing some values in a results array returned by ansible, when I debug the variable I registered from command module.
I am running multiple commands using with_items and register the result in a "registeredVar". I tried to access the results like this registeredVar.results.stdout but I get "VARIABLE IS NOT DEFINED!" error.
I also tried to loop through the results array in the debug task, but i get a "object' has no attribute 'stdout'" error
Below are the tasks I am running
- name: check configuration
shell: "{{ item }}"
register: falcon_config
with_items:
- /opt/CrowdStrike/falconctl -g --aph
- /opt/CrowdStrike/falconctl -g --cid
- /opt/CrowdStrike/falconctl -g --app
Below is the debug task to output the variable
- debug:
var: falcon_config['results'].stdout
alternativley:
- debug:
var: '{{ item.stdout }}'
with_items: falcon_config['results']
This is the debug output of the results array when run falcon_config['results']
"falcon_config['results']": [
{
"_ansible_ignore_errors": null,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/CrowdStrike/falconctl -g --aph",
"delta": "0:00:00.006724",
"end": "2019-07-29 10:36:05.481672",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/CrowdStrike/falconctl -g --aph",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/opt/CrowdStrike/falconctl -g --aph",
"rc": 0,
"start": "2019-07-29 10:36:05.474948",
"stderr": "",
"stderr_lines": [],
"stdout": "aph=crowdstrike.domain.",
"stdout_lines": [
"aph=crowdstrike.intra.absaafrica."
]
},
{
"_ansible_ignore_errors": null,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/CrowdStrike/falconctl -g --cid",
"delta": "0:00:00.006716",
"end": "2019-07-29 10:36:05.662173",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/CrowdStrike/falconctl -g --cid",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/opt/CrowdStrike/falconctl -g --cid",
"rc": 0,
"start": "2019-07-29 10:36:05.655457",
"stderr": "",
"stderr_lines": [],
"stdout": "cid=\"185d26e78791sksdasd9d1033sa4\".",
"stdout_lines": [
"cid=\"185d26e78791sksdasd9d1033sa4\"."
]
},
{
"_ansible_ignore_errors": null,
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/opt/CrowdStrike/falconctl -g --app",
"delta": "0:00:00.006617",
"end": "2019-07-29 10:36:05.840573",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/opt/CrowdStrike/falconctl -g --app",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/opt/CrowdStrike/falconctl -g --app",
"rc": 0,
"start": "2019-07-29 10:36:05.833956",
"stderr": "",
"stderr_lines": [],
"stdout": "app=8080.",
"stdout_lines": [
"app=8080."
]
}
]
}
I cant get the stdout value of each object.
You can use the json_query filter:
- debug:
var: falcon_config | json_query('results[*].stdout')
This will also work as input to a loop
The problem you have is that when you register the output of a module on a loop, you end up with a list. So, on the line var: falcon_config['results'].stdout it fails because falcon_config['results'] is a list and doesn't have a stdoud key. You have to access this result inside a loop.
Ths snippet you've included should work:
- debug:
var: '{{ item.stdout }}'
with_items: falcon_config['results']
I tested your code with the following playbook, and it does:
---
- hosts: local
connection: local
gather_facts: no
tasks:
- name: Run all shell commands
shell: '{{ item }}'
register: falcon_config
with_items:
- 'echo Hello World'
- 'echo Something'
- 'echo lorem ipsum'
- name: Debug the results
debug:
var: item["stdout"]
with_items: '{{ falcon_config["results"] }}'
I hope it helps

Debug not working with_items in ansible play

Need some help in debug the specific value from register task.
- debug:
msg: "{{ item.stdout }}"
with_items: path_result.results
This is not working
{
"changed": false,
"path_result": {
"msg": "All items completed",
"changed": true,
"results": [
{
"_ansible_parsed": true,
"stderr_lines": [],
"_ansible_item_result": true,
"end": "2019-04-10 14:55:18.726270",
"_ansible_no_log": false,
"_ansible_delegated_vars": {
"ansible_delegated_host": "**.***.***.***",
"ansible_host": "**.***.***.***"
},
"cmd": "cat /tmp/abc.conf | grep apple",
"rc": 0,
"stdout": "fruit=apple",
"item": "**.***.***.***",
"delta": "0:00:00.021499",
"stderr": "",
"changed": true,
"invocation": {
"module_args": {
"creates": null,
"executable": null,
"_uses_shell": true,
"_raw_params": "cat /tmp/abc.conf | grep apple",
"removes": null,
"warn": true,
"chdir": null,
"stdin": null
}
},
"stdout_lines": [
"fruit=apple"
],
"start": "2019-04-10 14:55:18.704771",
"_ansible_ignore_errors": null,
"failed": false
}
]
},
"_ansible_verbose_always": true,
"_ansible_no_log": false
}
I would like to debug this particular output:
"stdout": "fruit=apple"
It looks like you have registered the result of a play with: register: path_result. That variable ALSO has path_result inside it. Here's what I think you have:
- command: cat /tmp/abc.conf | grep apple
register: path_result
- debug:
msg: "{{ item.stdout }}"
with_items: "{{ path_result.results }}"
Here's what I think you need:
- command: cat /tmp/abc.conf | grep apple
register: path_result
- debug:
msg: "{{ item.stdout }}"
with_items: "{{ path_result.path_result.results }}"
Notice the added .path_result part in with_items.

Ansible - Registered Variable Usage In Loop

I would like to have git update with two different items (mango and apple) and in the next step display each individual checkout's latest versions.
- name: Checkout Mango and Apple
git:
repo: ssh://user#gerrit.adap.tv:26545/{{ item }}.git
dest: "{{ scriptdir }}/{{ item }}"
key_file: "{{ rsa_key }}"
accept_hostkey: yes
update: yes
with_items:
- mango
- apple
register: checkoutVersion
- name: Display the checkoutVersion
debug: msg="Checkout Version is {{ item.name }}"
with_items:
- checkoutVersion.after
Code Output :-
TASK: [makePkg | Checkout Mango and Apple ] **********************************************
ok: [127.0.0.1] => (item=mango) => {"after": "d3aa6131ec1a2e73f69ee150", "before": "d3aa6131ec1a2e73f69ee150", "changed": false, "item": "mango"}
ok: [127.0.0.1] => (item=primeribs) => {"after": "f9bb03466f248a9eb92c9656", "before": "f9bb03466f248a9eb92c9656", "changed": false, "item": "apple"}
TASK: [makePkg | Display the checkoutVersion] *********************************
fatal: [127.0.0.1] => One or more undefined variables: 'str object' has no attribute 'item'
FATAL: all hosts have already failed -- aborting
Please suggest how can I print each individual item's latest version.
I find that the best thing to do in a case like this is to write a small test case to see exactly how ansible behaves. For example:
- hosts: localhost
gather_facts: False
tasks:
- command: /bin/echo {{ item }}
register: foo
with_items:
- one
- two
- three
- debug: var=foo
The output of the above playbook shows how ansible stores the results of the loop in the variable foo:
ok: [localhost] => {
"foo": {
"changed": true,
"msg": "All items completed",
"results": [
{
"changed": true,
"cmd": [
"/bin/echo",
"one"
],
"delta": "0:00:00.027182",
"end": "2015-08-19 13:13:25.216657",
"invocation": {
"module_args": "/bin/echo one",
"module_name": "command"
},
"item": "one",
"rc": 0,
"start": "2015-08-19 13:13:25.189475",
"stderr": "",
"stdout": "one"
},
{
"changed": true,
"cmd": [
"/bin/echo",
"two"
],
"delta": "0:00:00.006270",
"end": "2015-08-19 13:13:25.509316",
"invocation": {
"module_args": "/bin/echo two",
"module_name": "command"
},
"item": "two",
"rc": 0,
"start": "2015-08-19 13:13:25.503046",
"stderr": "",
"stdout": "two"
},
{
"changed": true,
"cmd": [
"/bin/echo",
"three"
],
"delta": "0:00:00.006347",
"end": "2015-08-19 13:13:25.763675",
"invocation": {
"module_args": "/bin/echo three",
"module_name": "command"
},
"item": "three",
"rc": 0,
"start": "2015-08-19 13:13:25.757328",
"stderr": "",
"stdout": "three"
}
]
}
}
So the actual results are provided in the list foo.results. If we change the debug task slightly we can iterate through these results one by one:
- debug: var=item
with_items: foo.results
This returns the following:
ok: [localhost] => (item={u'stdout': u'one', u'changed': True, u'end': u'2015-08-19 13:17:39.884374', 'item': 'one', u'cmd': [u'/bin/echo', u'one'], u'rc': 0, u'start': u'2015-08-19 13:17:39.878585', u'stderr': u'', u'delta': u'0:00:00.005789', 'invocation': {'module_name': u'command', 'module_args': u'/bin/echo one'}}) => {
"item": {
"changed": true,
"cmd": [
"/bin/echo",
"one"
],
"delta": "0:00:00.005789",
"end": "2015-08-19 13:17:39.884374",
"invocation": {
"module_args": "/bin/echo one",
"module_name": "command"
},
"item": "one",
"rc": 0,
"start": "2015-08-19 13:17:39.878585",
"stderr": "",
"stdout": "one"
}
}
ok: [localhost] => (item={u'stdout': u'two', u'changed': True, u'end': u'2015-08-19 13:17:40.137575', 'item': 'two', u'cmd': [u'/bin/echo', u'two'], u'rc': 0, u'start': u'2015-08-19 13:17:40.131803', u'stderr': u'', u'delta': u'0:00:00.005772', 'invocation': {'module_name': u'command', 'module_args': u'/bin/echo two'}}) => {
"item": {
"changed": true,
"cmd": [
"/bin/echo",
"two"
],
"delta": "0:00:00.005772",
"end": "2015-08-19 13:17:40.137575",
"invocation": {
"module_args": "/bin/echo two",
"module_name": "command"
},
"item": "two",
"rc": 0,
"start": "2015-08-19 13:17:40.131803",
"stderr": "",
"stdout": "two"
}
}
ok: [localhost] => (item={u'stdout': u'three', u'changed': True, u'end': u'2015-08-19 13:17:40.368420', 'item': 'three', u'cmd': [u'/bin/echo', u'three'], u'rc': 0, u'start': u'2015-08-19 13:17:40.362533', u'stderr': u'', u'delta': u'0:00:00.005887', 'invocation': {'module_name': u'command', 'module_args': u'/bin/echo three'}}) => {
"item": {
"changed": true,
"cmd": [
"/bin/echo",
"three"
],
"delta": "0:00:00.005887",
"end": "2015-08-19 13:17:40.368420",
"invocation": {
"module_args": "/bin/echo three",
"module_name": "command"
},
"item": "three",
"rc": 0,
"start": "2015-08-19 13:17:40.362533",
"stderr": "",
"stdout": "three"
}
}
So I would suggest that you first change your debug task to be just this initially:
- name: Display the checkoutVersion
debug: var=checkoutVersion
Use this to see exactly what sort of output the git module provides, then expand on that to do exactly what you want.
Given the output that you did provide above, then the final debug statement you'll want is something along these lines:
- name: Display the checkoutVersion
debug: msg="Checkout Version is {{ item.after }}"
with_items: checkoutVersion.results

Resources