Я нахожу, что лучше всего в таком случае написать небольшой тестовый пример, чтобы точно увидеть, как это работает. Например:
- hosts: localhost
gather_facts: False
tasks:
- command: /bin/echo {{ item }}
register: foo
with_items:
- one
- two
- three
- debug: var=foo
Выход выше пьес показывает, как анзибль сохраняет результаты цикла в переменной 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"
}
]
}
}
Таким образом, фактические результаты представлены в списке foo.results
. Если мы изменим задачу отладки немного мы можем перебирать эти результаты один за другим:
- debug: var=item
with_items: foo.results
Это возвращает следующее:
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"
}
}
Так что я хотел бы предложить, что вы первый изменить debug
задачу быть просто это изначально:
- name: Display the checkoutVersion
debug: var=checkoutVersion
Используйте это, чтобы увидеть какую именно вывод git
модуля обеспечивает, а затем разверните на том, чтобы сделать точно что ты хочешь.
Учитывая вывод, что ты предоставить выше, то окончательное утверждение отладки вы хотите что-то вдоль этих линий:
- name: Display the checkoutVersion
debug: msg="Checkout Version is {{ item.after }}"
with_items: checkoutVersion.results