How to use the ansible_env.ProgramFiles(x86) variable

I’ve been trying to use this variable (host is a windows 2K12 machine), but I guess the parsers trip over the brackets/parentheses in the name in the last task … Previous tasks all work correct. Should be better to rename the variable to something without brackets

The test playbook is:

  • hosts: Myserver
    gather_facts: true

pre_tasks:

  • name: env
    debug:
    var: ansible.env

  • name: ProgramFiles
    debug:
    var: ansible_env.ProgramFiles

  • name: ProgramFiles
    debug:
    var: ansible_env.ProgramFiles(x86)

ansible fails on the last task with:

TASK [ProgramFiles] ************************************************************

task path: /home/noel/work/ivv-test/ansible/test.yml:14

An exception occurred during task execution. The full traceback is:

Traceback (most recent call last):

File “/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 126, in run

res = self._execute()

File “/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py”, line 502, in _execute

result = self._handler.run(task_vars=variables)

File “/usr/lib/python2.7/site-packages/ansible/plugins/action/debug.py”, line 57, in run

results = self._templar.template(self._task.args[‘var’], convert_bare=True, fail_on_undefined=True, bare_deprecated=False)

File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 383, in template

disable_lookups=disable_lookups,

File “/usr/lib/python2.7/site-packages/ansible/template/init.py”, line 583, in do_template

res = j2_concat(rf)

File “”, line 9, in root

File “/usr/lib/python2.7/site-packages/jinja2/runtime.py”, line 177, in call

fn = __obj.call

AttributeError: ‘AnsibleUnsafeText’ object has no attribute ‘call

fatal: [chat01]: FAILED! => {

“failed”: true,

“msg”: “Unexpected failure during module execution.”,

“stdout”: “”

}

to retry, use: --limit @./retry-files/test.retry

Regards, Noel

Use the other way of specifying a python hash key, like this:

`

  • hosts: Myserver
    gather_facts: true

pre_tasks:

  • name: env
    debug:
    var: ansible.env

  • name: ProgramFiles
    debug:
    var: ansible_env[‘ProgramFiles’]

  • name: ProgramFiles(x86)
    debug:
    var: ansible_env[‘ProgramFiles(x86)’]
    `

As you can see it will work for either.

Hope this helps,

Jon

Thanks, that works.