我有一个非常简单的Ansible设置。
group_vars/all/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是否可以从命令行中删除我自己的变量?
答案 0 :(得分:1)
需要2件事:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="city"></div>
以JSON格式传递散列--extra-var:
hash_behaviour = merge
答案 1 :(得分:1)
group_vars/all/main.yml:
不是推荐的,更喜欢做事的方式。我可以告诉你更优雅的方式:
<强> symfony:
env: "{{ ENV }}"
owner: capistrano
cache_owner: files
cache_group: files
deploy_base: /opt/symfony
keep_count: 2
deploy_version: "{{ DEPLOY_VERSION }}"
deploy_hosts: "{{ DEPLOY_HOSTS }}"
强>
/usr/bin/ansible-playbook deploy.yml -i inventory/hosts \
-e "DEPLOY_HOSTS=stg-web" \
-e "DEPLOY_VERSION$UPSTREAM_BUILD_NUMBER" \
-e "ENV=stg"
然后像这样打电话给你的Ansible:
{{1}}
希望能帮到你!