我已经在 ansible 存储库上填写了一个问题,但我想确认它确实是一个错误并且我没有做错任何事情。 https://github.com/ansible/ansible/issues/14945
当主机组在剧本中更改时,似乎不会重新加载 group_vars 中定义的变量。
这是我使用 ansible 2.0.1.0 的剧本
├── inventory
│ └── dev
│ ├── group_vars
│ │ ├── all
│ │ ├── backend
│ │ └── backoffice
│ └── hosts
├── playbook.yml
└── roles
└── deploy
└── tasks
└── main.yml
主机中的库存:
[shop]
weenect.dev ansible_user=vagrant
[backend]
weenect.dev ansible_user=vagrant
[backoffice]
weenect.dev ansible_user=vagrant
为每个主机组执行的部署角色中的任务:
---
- debug: msg="{{ deploy_source_folder }}"
这个变量的值:
inventory/dev/group_vars/all 的内容:
---
deploy_source_folder: "default"
inventory/dev/group_vars/backend 的内容:
---
deploy_source_folder: "backend"
inventory/dev/group_vars/backoffice 的内容:
---
deploy_source_folder: "backoffice"
执行我的剧本时,预期的结果是:
Debug of deploy_source_folder for backend : "backend"
Debug of deploy_source_folder for backoffice : "backoffice"
Debug of deploy_source_folder for shop : "default"
但相反,我有:
Debug of deploy_source_folder for backend : "backend"
Debug of deploy_source_folder for backoffice : "backend"
Debug of deploy_source_folder for shop : "backend"