when I run ansible-playbook test.yml --extra-vars "var2=foo"
gives error:
AnsibleError: template error while templating string: expected token ':', got '}'.
If I substitute the value of var2 with foo in template playbook runs successfully.
I tried below things ansible fails throwing same error
a, with_items: {{foo}} and did {{item}} in playbook it doesn't work.
b. set_fact
-var2: foo
ACTUAL RESULTS
hostname.yml should contain
site: xyz.com
owner: test
Thanks Brian for taking time. I got whole playbook working with static values.
Below is how I structured foo. If I substitute template var2 with foo. it works fine.
Thanks Brian - I am looking for away so that var2 passed to ansible-playbook template as extra-vars is interpreted as dict in vars/main.yml.
When I add var2=foo in inventory. I get dict object has no attribute u’foo’
I now see var2 passed to template. ansible complains
Error: str has no iteritems.
when template has var2. where var2 is passed as extra_vars.
Error: dict object has no attribute ‘foo’
when var2 =foo was added inventory variables.
I am hitting dead end with ansible way of substituting template variable via roles.
I wrote command task to replace template variable before template task is called.