пытается установить условие перезапуска экземпляра EC2, если после установки функций Windows требуется перезагрузка.
- name: Install IIS Web-Server
win_feature:
name: '{{ item }}'
state: present
loop: '{{ win_features }}'
register: register_win_feature
- debug:
var: register_win_feature
отладка показывает это:
{
"register_win_feature": {
"msg": "All items completed",
"changed": false,
"results": [
{
"_ansible_parsed": true,
"feature_result": [],
"_ansible_item_result": true,
"_ansible_item_label": "Web-Server",
"success": true,
"failed": false,
"_ansible_no_log": false,
"changed": false,
"reboot_required": false,
"item": "Web-Server",
"restart_needed": false,
"_ansible_ignore_errors": null,
"exitcode": "NoChangeNeeded"
},
{
"_ansible_parsed": true,
"feature_result": [],
"_ansible_item_result": true,
"_ansible_item_label": "Web-Asp-Net45",
"success": true,
"failed": false,
"_ansible_no_log": false,
"changed": false,
"reboot_required": false,
"item": "Web-Asp-Net45",
"restart_needed": false,
"_ansible_ignore_errors": null,
"exitcode": "NoChangeNeeded"
},
{
"_ansible_parsed": true,
"feature_result": [],
"_ansible_item_result": true,
"_ansible_item_label": "Web-Net-Ext45",
"success": true,
"failed": false,
"_ansible_no_log": false,
"changed": false,
"reboot_required": false,
"item": "Web-Net-Ext45",
"restart_needed": false,
"_ansible_ignore_errors": null,
"exitcode": "NoChangeNeeded"
},
{
"_ansible_parsed": true,
"feature_result": [],
"_ansible_item_result": true,
"_ansible_item_label": "Web-Windows-Auth",
"success": true,
"failed": false,
"_ansible_no_log": false,
"changed": false,
"reboot_required": false,
"item": "Web-Windows-Auth",
"restart_needed": false,
"_ansible_ignore_errors": null,
"exitcode": "NoChangeNeeded"
}
]
},
"changed": false,
"_ansible_verbose_always": true,
"_ansible_no_log": false
}
Тогда, если я использую этот модуль:
- name: reboot if installing Web-Server feature requires it
win_reboot:
when: register_win_feature.results.reboot_required == true
модуль не сработает, потому что выход - это список
"msg": "The conditional check 'register_win_feature.results.reboot_required == true' failed. The error was: error while evaluating conditional (register_win_feature.results.reboot_required == true): 'list object' has no attribute 'reboot_required'\n\nThe error appears to have been in '/var/lib/awx/projects/_5378__256_bowtie_test/roles/enx_bowtie_server/tasks/main.yml': line 35, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: reboot if installing Web-Server feature requires it\n ^ here\n",
"_ansible_no_log": false
, если я добавлю [*] для циклического перебора всех результатовсписок, он не распознает это. Он также не работает:
- name: reboot if installing Web-Server feature requires it
win_reboot:
when: register_win_feature.results[*].reboot_required == true
"msg": "The conditional check 'register_win_feature.results[*].reboot_required == true' failed. The error was: template error while templating string: unexpected '*'. String: {% if register_win_feature.results[*].reboot_required == true %} True {% else %} False {% endif %}\n\nThe error appears to have been in '/var/lib/awx/projects/_5378__256_bowtie_test/roles/enx_bowtie_server/tasks/main.yml': line 35, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: reboot if installing Web-Server feature requires it\n ^ here\n",
"_ansible_no_log": false
Не удается заставить его работать. Я искал в Интернете аналогичную проблему, но безуспешно.
:( любая помощь будет очень ценна.