當測試:ansible 2.2.0.0,2.2.1.0 & 2.1.4.0ansible返回不正確的使用瓦爾動態庫存
我有一個庫存腳本返回運行時,此JSON(最小例如的緣故):
{
"componentA-service_ci": {
"hosts": [
"host1.example.com",
"host2.example.com"
],
"vars": {
"httpport": "8100",
"nginxpool": "componentA_pool"
}
},
"componentB-service_ci": {
"hosts": [
"host1.example.com",
"host3.example.com"
],
"vars": {
"httpport": "9999",
"nginxpool": "componentB_pool"
}
}
}
我正在編寫的劇本是用於部署應用程序。庫存中的變量對於組是唯一的,即每個服務都有自己的lb池和http端口。在一臺主機上也可以有多個應用程序。這裏是什麼劇本喜歡就好:
---
- hosts: all
remote_user: deployment
become: true
become_method: sudo
become_user: root
gather_facts: yes
serial: 1
roles:
- app-deploy
在角色中的任務只是輸出變量nginxpool和HTTPPORT。
我運行的劇本是這樣的:
ansible-playbook deploy.yml -i inventory.py --limit componentA-service_ci
預期結果:
實際結果:
TASK [app-deploy : debug] ******************************************************
ok: [host1.example.com] => {
"msg": "pool componentB_pool port 9999"
}
TASK [app-deploy : debug] ******************************************************
ok: [host2.example.com] => {
"msg": "pool componentA_pool port 8100"
}
的--limit
作品該組件可以在組件A-service_ci中列出的主機上進行部署,對於host1.example.com組件則可以部署。我從componentB-service_ci vars中獲取nginxpool和httpport的值。我讀了documentation,但不明白這是怎麼發生的?這是一個錯誤還是我只是不理解這裏有多麼可行的作品?
可能重複[在特定主機組上運行](http://stackoverflow.com/questions/41500463/run-ansible-on-specific-hosts-group) – techraf