Configuration-Management

如何啟用 Ansible 和 Vagrant 的額外調試輸出?

  • June 13, 2017

我正在調查 Ansible 的伺服器和應用程序配置。我的應用程序目前在 Vagrant 中配置了 shell 腳本。我沒有重寫我的腳本,而是取了一個樣本並嘗試部署它。

它似乎部署得很好,但是在一系列成功的步驟之後,我看到了一條失敗消息:

» vagrant provision                                       ~/vm/blvagrant 1 ↵
[default] Running provisioner: ansible...

PLAY [web-servers] ************************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.9.149]

TASK: [install python-software-properties] ************************************
ok: [192.168.9.149] => {"changed": false, "item": ""}

TASK: [add nginx ppa if it ubuntu 10.04 and up] *******************************
ok: [192.168.9.149] => {"changed": false, "item": "", "repo": "ppa:nginx/stable", "state": "present"}

TASK: [update apt repo] *******************************************************
ok: [192.168.9.149] => {"changed": false, "item": ""}

TASK: [install nginx] *********************************************************
ok: [192.168.9.149] => {"changed": false, "item": ""}

TASK: [copy fixed init for nginx] *********************************************
ok: [192.168.9.149] => {"changed": false, "gid": 0, "group": "root", "item": "", "mode": "0755", "owner": "root", "path": "/etc/init.d/nginx", "size": 2321, "state": "file", "uid": 0}

TASK: [service nginx] *********************************************************
ok: [192.168.9.149] => {"changed": false, "item": "", "name": "nginx", "state": "started"}

TASK: [write nginx.conf] ******************************************************
ok: [192.168.9.149] => {"changed": false, "gid": 0, "group": "root", "item": "", "mode": "0644", "owner": "root", "path": "/etc/nginx/nginx.conf", "size": 1067, "state": "file", "uid": 0}

PLAY RECAP ********************************************************************
192.168.9.149              : ok=8    changed=0    unreachable=0    failed=0

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

如何獲取額外的調試資訊?我已經添加ansible.verbose = true到我的 vagrant 配置中,這導致字典顯示在上面的輸出中。

你也可以將它添加到你的 Vagrantfile 中:

ansible.verbose = "vvv"

這需要轉到您開始配置的地方,如下所示:

config.vm.provision "ansible" do |ansible|
   ansible.verbose = "vvv"
end

這設置了 ansible 的詳細選項:

-v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                       connection debugging)

將此設置為vvvv(四個 v)對於調試 SSH 連接錯誤很有用 - 但它會產生大量調試輸出,因此如果您遇到連接問題,請僅使用四個 v。

引用自:https://serverfault.com/questions/531891