-1

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

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

ANSIBLE 版本

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 }}"

配置

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": ""
                    }
                }
            ]
        }

如何获得预期的输出?

4

1 回答 1

-1

看起来您正在运行您的剧本,并启用了更高级别的详细信息(我猜您正在运行类似的东西,ansible-playbook playbook.yml -v而不仅仅是 `ansible-playbook playbook.yml)。

尝试运行ansible-playbook没有设置详细标志的命令。

于 2018-05-25T12:56:31.527 回答