Ansible: Passing evaluated variables to includes -



Ansible: Passing evaluated variables to includes -

i have ansible playbook makes phone call playbook passing in parameters. works fine, when seek pass in variables, ansible blows up. here playbook:

--- - name: toplevel play orchestration hosts: nogroup vars: customer: mycustomer sudo: yes - include: amazon.yml application=fooserver instance_type=t2.micro instance_count=1 customer={{ client }} - include: amazon.yml application=barserver instance_type=t2.micro instance_count=1 customer={{ client }}

i seek run:

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

and error:

traceback (most recent phone 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 1 value unpack

any ideas on how allow me pass variable set on command line downwards through multiple levels of includes in playbook?

thanks ahead of time!

without more context hard reproduce issue guess problem comes fact you're trying assign variable customer itself.

variables defined on play inherited subsequent include statements. so, there's no need append customer={{customer}} @ end of include statements since have defined @ play level via:

vars: customer: mycustomer

note: variable overridden new value set via command line -e option.

try playbook this:

--- - name: toplevel play orchestration hosts: nogroup vars: customer: mycustomer sudo: yes - include: amazon.yml application=fooserver instance_type=t2.micro instance_count=1 - include: amazon.yml application=barserver instance_type=t2.micro instance_count=1

and utilize evaluated {{customer}} on tasks within file amazon.yml.

ansible

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -