How to use the ansible_env.ProgramFiles(x86) variable

1,040 views
Skip to first unread message

Noel Verhoeven

unread,
Apr 6, 2017, 3:45:54 AM4/6/17
to Ansible Project
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 "<template>", 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

J Hawkesworth

unread,
Apr 6, 2017, 9:33:58 AM4/6/17
to Ansible Project
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

Noel Verhoeven

unread,
Apr 6, 2017, 10:35:10 AM4/6/17
to Ansible Project
Thanks, that works.
Reply all
Reply to author
Forward
0 new messages