@oni__ino

Как в ansible вывести сообщение об ошибке msg="" а не весь stdout переменной?

localhost: ubuntu 14.04
ansible: v2.0.1.0 (настройки дефолтные)
client_host: redhat 5

- name: Register variable (using with_items)
  command: mountpoint "{{ item }}"
  with_items: ["/mnt/iso", "/mnt/test"]
  register: RTR
  ignore_errors: yes

- debug: var=RTR

- name: Fail if return code is not 0
  fail: msg="{{RTR.results[0].stdout}}"
  when: item.rc != 0
  with_items: "{{RTR.results}}"


Получаю вывод:
TASK [proj-***-test : Fail if return code is not 0] **************************
skipping: [proj-***-test] => (item={u'stdout': u'/mnt/iso is a mountpoint', u'cmd': [u'mountpoint', u'/mnt/iso'], u'end': u'2016-04-06 14:29:38.181588', '_ansible_no_log': False, u'warnings': [], u'changed': True, u'start': u'2016-04-06 14:29:38.171837', u'delta': u'0:00:00.009751', 'item': u'/mnt/iso', u'rc': 0, 'invocation': {'module_name': u'command', u'module_args': {u'creates': None, u'executable': None, u'chdir': None, u'_raw_params': u'mountpoint "/mnt/iso"', u'removes': None, u'warn': True, u'_uses_shell': False}}, 'stdout_lines': [u'/mnt/iso is a mountpoint'], u'stderr': u''}) 
failed: [proj-***-test] => (item={u'changed': True, u'stdout': u'/mnt/test is not a mountpoint', '_ansible_no_log': False, 'stdout_lines': [u'/mnt/test is not a mountpoint'], u'warnings': [], 'item': u'/mnt/test', u'cmd': [u'mountpoint', u'/mnt/test'], 'failed': True, u'delta': u'0:00:00.010001', u'stderr': u'', u'rc': 1, 'invocation': {'module_name': u'command', u'module_args': {u'creates': None, u'executable': None, u'chdir': None, u'_raw_params': u'mountpoint "/mnt/test"', u'removes': None, u'warn': True, u'_uses_shell': False}}, u'end': u'2016-04-06 14:29:38.435078', u'start': u'2016-04-06 14:29:38.425077'}) => {"failed": true, "item": {"_ansible_no_log": false, "changed": true, "cmd": ["mountpoint", "/mnt/test"], "delta": "0:00:00.010001", "end": "2016-04-06 14:29:38.435078", "failed": true, "invocation": {"module_args": {"_raw_params": "mountpoint \"/mnt/test\"", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "item": "/mnt/test", "rc": 1, "start": "2016-04-06 14:29:38.425077", "stderr": "", "stdout": "/mnt/test is not a mountpoint", "stdout_lines": ["/mnt/test is not a mountpoint"], "warnings": []}, "msg": "/mnt/iso is a mountpoint"}
	to retry, use: --limit @test-playbook.retry

PLAY RECAP *********************************************************************
proj-***-test               : ok=5    changed=0    unreachable=0    failed=1

Почему вывод информации идет по такому странному шаблону u' ** ': u' ** ', u' ** ' ---вот так u'stdout': u'/mnt/iso is a mountpoint', u'cmd' а не например с переходами на следующую строку, не очень удобно читается, может я и придераюсь

Вопрос как получить ответ только в "stdout": "/mnt/test is not a mountpoint", или "stdout_lines": "/mnt/test is not a mountpoint" потому, что если указывать msg="{{RTR.results[0].stdout_lines}}" или RTR.results[0].results.stdout_lines ругается вот так: fatal: [*****]: FAILED! => {"failed": true, "msg": "'unicode object' has no attribute 'stdout_lines'"}

Вывод со строки переменной - debug: var=RTR
TASK [proj-***-test : debug] *************************************************
ok: [proj-***-test] => {
    "RTR": {
        "changed": true, 
        "failed": true, 
        "msg": "One or more items failed", 
        "results": [
            {
                "_ansible_no_log": false, 
                "changed": true, 
                "cmd": [
                    "mountpoint", 
                    "/mnt/iso"
                ], 
                "delta": "0:00:00.009751", 
                "end": "2016-04-06 14:29:38.181588", 
                "invocation": {
                    "module_args": {
                        "_raw_params": "mountpoint \"/mnt/iso\"", 
                        "_uses_shell": false, 
                        "chdir": null, 
                        "creates": null, 
                        "executable": null, 
                        "removes": null, 
                        "warn": true
                    }, 
                    "module_name": "command"
                }, 
                "item": "/mnt/iso", 
                "rc": 0, 
                "start": "2016-04-06 14:29:38.171837", 
                "stderr": "", 
                "stdout": "/mnt/iso is a mountpoint", 
                "stdout_lines": [
                    "/mnt/iso is a mountpoint"
                ], 
                "warnings": []
            }, 
            {
                "_ansible_no_log": false, 
                "changed": true, 
                "cmd": [
                    "mountpoint", 
                    "/mnt/test"
                ], 
                "delta": "0:00:00.010001", 
                "end": "2016-04-06 14:29:38.435078", 
                "failed": true, 
                "invocation": {
                    "module_args": {
                        "_raw_params": "mountpoint \"/mnt/test\"", 
                        "_uses_shell": false, 
                        "chdir": null, 
                        "creates": null, 
                        "executable": null, 
                        "removes": null, 
                        "warn": true
                    }, 
                    "module_name": "command"
                }, 
                "item": "/mnt/test", 
                "rc": 1, 
                "start": "2016-04-06 14:29:38.425077", 
                "stderr": "", 
                "stdout": "/mnt/test is not a mountpoint", 
                "stdout_lines": [
                    "/mnt/test is not a mountpoint"
                ], 
                "warnings": []
            }
        ]
    }
}


И гляньте еще мой вопрос, если знаете как помочь...
Почему в логе работы ansible не работают переносы ...
  • Вопрос задан
  • 1239 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы