我有一个非常简单的Ansible设置.
group_vars /所有/ main.yml:
symfony:
env: prod
owner: capistrano
cache_owner: files
cache_group: files
deploy_base: /opt/symfony
keep_count: 2
deploy.yml:
# ...
- name: roll forward latest release
symfony_preload: version="{{ symfony.deploy_version }}" deploy_base="{{ symfony.deploy_base }}"
事实上,这个模块确实起作用,这就是Ansible似乎没有正确加载变量.我这样叫Ansible:
/usr/bin/ansible-playbook deploy.yml -i inventory/hosts \
-e deploy_hosts=stg-web \
-e symfony.deploy_version="$UPSTREAM_BUILD_NUMBER" \
-e symfony.env="stg"
这失败了:
TASK [roll forward latest release] *********************************************
fatal: [webserver1]: FAILED! => {"failed": true, "msg": "'symfony' is undefined"}
这里失败了什么? Ansible是否从命令行中删除了我自己的变量?
最佳答案 需要2件事:
>在ansible.cfg中指定hash_behaviour = merge
>以JSON格式传递散列–extra-var:
→ansible-playbook playbooks / variables-demo.yml -e'{“symfony”:{“deploy_version”:“y”,“deploy_base”:“/ some / other”}}’