调试= ON的Ansible JSON输出

时间:2018-05-25 11:39:44

标签: ansible ansible-2.x

当我运行一个剧本时,我将命令输出注册到一个寄存器上并将其分配给msg,调试为true,我的ansible.cfg如下所示 stdout_callback = json retry_files_enabled = False

我得到了所需的“主机”输出2次。

不合适的版本

ansible 2.5.2

组件名称

module: shell

示例任务如下所示:

- name: MongoDB Auth check
  script: files/mongoAuthCheck.sh
  register: mongoAuthCheck_out
  changed_when: false

- debug:
   msg: "{{ mongoAuthCheck_out.stdout_lines }}"

CONFIGURATION

ANSIBLE_NOCOWS(xx/xx/xx/ansible.cfg) = True
CACHE_PLUGIN(xx/xx/xx/ansible.cfg) = jsonfile
DEFAULT_GATHERING(xx/xx/xx/ansible.cfg) = smart
DEFAULT_STDOUT_CALLBACK(xx/xx/xx/ansible.cfg) = json
HOST_KEY_CHECKING(xx/xx/xx/ansible.cfg) = False
RETRY_FILES_ENABLED(/xx/xx/xx/ansible.cfg) = False

预期成果

"tasks": [
                {
                    "hosts": {
                        "10.140.0.15": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "Unit mongod.service could not be found.", 
                                "[INFO] Mongo service not running"
                            ]
                        }, 
                        "10.140.0.18": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "Failed global initialization: BadValue Invalid or no user locale set.  Please ensure LANG and/or LC_* environment variables are set correctly. locale::facet::_S_create_c_locale name not valid", 
                                "[VULNERABLE] MongoDB auth is NOT enabled"
                            ]
                        }, 
                        "10.140.0.22": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "[INFO] Mongo service not running"
                            ]
                        }
                    }, 
                    "task": {
                        "id": "d6002031-f201-2ec3-be9f-000000000026", 
                        "name": ""
                    }
                }
            ]
        }

实际结果

"tasks": [
                {
                    "hosts": {
                        "10.140.0.15": {
                            "_ansible_no_log": false, 
                            "changed": false, 
                            "rc": 0, 
                            "stderr": "Shared connection to 10.140.0.15 closed.\r\n", 
                            "stdout": "Unit mongod.service could not be found.\r\n[INFO] Mongo service not running\r\n", 
                            "stdout_lines": [
                                "Unit mongod.service could not be found.", 
                                "[INFO] Mongo service not running"
                            ]
                        }, 
                        "10.140.0.18": {
                            "_ansible_no_log": false, 
                            "changed": false, 
                            "rc": 0, 
                            "stderr": "Shared connection to 10.140.0.18 closed.\r\n", 
                            "stdout": "Failed global initialization: BadValue Invalid or no user locale set.  Please ensure LANG and/or LC_* environment variables are set correctly. locale::facet::_S_create_c_locale name not valid\r\n[VULNERABLE] MongoDB auth is NOT enabled\r\n", 
                            "stdout_lines": [
                                "Failed global initialization: BadValue Invalid or no user locale set.  Please ensure LANG and/or LC_* environment variables are set correctly. locale::facet::_S_create_c_locale name not valid", 
                                "[VULNERABLE] MongoDB auth is NOT enabled"
                            ]
                        }, 
                        "10.140.0.22": {
                            "_ansible_no_log": false, 
                            "changed": false, 
                            "rc": 0, 
                            "stderr": "Shared connection to 10.140.0.22 closed.\r\n", 
                            "stdout": "[INFO] Mongo service not running\r\n", 
                            "stdout_lines": [
                                "[INFO] Mongo service not running"
                            ]
                        }
                    }, 
                    "task": {
                        "id": "d6002031-f201-2ec3-be9f-000000000025", 
                        "name": "MongoDB Auth check"
                    }
                }, 
                {
                    "hosts": {
                        "10.140.0.15": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "Unit mongod.service could not be found.", 
                                "[INFO] Mongo service not running"
                            ]
                        }, 
                        "10.140.0.18": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "Failed global initialization: BadValue Invalid or no user locale set.  Please ensure LANG and/or LC_* environment variables are set correctly. locale::facet::_S_create_c_locale name not valid", 
                                "[VULNERABLE] MongoDB auth is NOT enabled"
                            ]
                        }, 
                        "10.140.0.22": {
                            "_ansible_no_log": false, 
                            "_ansible_verbose_always": true, 
                            "changed": false, 
                            "msg": [
                                "[INFO] Mongo service not running"
                            ]
                        }
                    }, 
                    "task": {
                        "id": "d6002031-f201-2ec3-be9f-000000000026", 
                        "name": ""
                    }
                }
            ]
        }

如何获得预期的输出?

1 个答案:

答案 0 :(得分:-1)

看起来你正在运行你的剧本,启用了更高级别的详细程度(我猜你正在运行像ansible-playbook playbook.yml -v而不仅仅是'ansible-playbook playbook.yml)。

尝试运行ansible-playbook命令而不设置详细标记。