Ansible:将评估变量传递给包含

时间:2014-11-06 16:16:16

标签: ansible

我有一个Ansible Playbook,可以调用另一个传递参数的playbook。这很好,但是当我尝试传入变量时,Ansible会爆炸。这是我的剧本:

---
- name: This is the toplevel play for orchestration
  hosts: nogroup
  vars:
    customer: myCustomer
  sudo: yes
- include: amazon.yml application=FooServer instance_type=t2.micro instance_count=1 customer={{ customer }}
- include: amazon.yml application=BarServer instance_type=t2.micro instance_count=1 customer={{ customer }}

我试着跑:

ansible-playbook orchestration.yml -e "customer=otherCustomer"

我收到此错误:

Traceback (most recent call last):
  File "/usr/local/Cellar/ansible/1.7.2/libexec/bin/ansible-playbook", line 5, in <module>
    pkg_resources.run_script('ansible==1.7.2', 'ansible-playbook')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 492, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1350, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/Cellar/ansible/1.7.2/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg/EGG-INFO/scripts/ansible-playbook", line 309, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/Cellar/ansible/1.7.2/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg/EGG-INFO/scripts/ansible-playbook", line 191, in main
    force_handlers=options.force_handlers
  File "/usr/local/Cellar/ansible/1.7.2/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg/ansible/playbook/__init__.py", line 180, in __init__
    (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook, vars)
  File "/usr/local/Cellar/ansible/1.7.2/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg/ansible/playbook/__init__.py", line 271, in _load_playbook_from_file
    inc_vars, inc_path = self._get_include_info(play, basedir, play_vars)
  File "/usr/local/Cellar/ansible/1.7.2/lib/python2.7/site-packages/ansible-1.7.2-py2.7.egg/ansible/playbook/__init__.py", line 210, in _get_include_info
    (k,v) = t.split("=", 1)
ValueError: need more than 1 value to unpack

关于如何允许我将命令行中设置的变量传递到我的剧本中的多个级别包含的任何想法?

1 个答案:

答案 0 :(得分:7)

遇到同样的问题。解决如下:

---
- include: common.yml
- include: redis.yml
    redis_port="{{ airflow_redis_port }}"
    redis_bind="{{ airflow_redis_host }}"