Hi,

when using the include_module with the "file" parameter, it fails with

    AttributeError: 'NoneType' object has no attribute 'startswith'.


This works fine:

----- testmyvars_1.yml -----------
---
- hosts: '{{ target }}'
   gather_facts: no
   tasks:
    - include_vars: ./myvars_1.yml

    - name: "Test myvars.yml"
debug: msg='Variable {{ item.key }} is named "{{ item.value.name }}" and has the value {{item.value.value}}'
      with_dict: "{{ var }}"
$
----------------------------------


----- myvars_1.yml ---------------
---
var:
   A:
    name:  "Variable A"
    value: "aaa"

   B:
    name:  "Variable B"
    value: "bbb"
...
----------------------------------


$ ansible-playbook testmyvars_1.yml --extra-vars "target=MYHOST" \
                                     --ask-pass
SSH password:

PLAY [MYHOST] ************************************************************

TASK [include_vars] ************************************************************
ok: [MYHOST]

TASK [Test myvars.yml] ********************************************************* ok: [MYHOST] => (item={'value': {u'name': u'Variable A', u'value': u'aaa'}, 'key': u'A'}) => {
     "item": {
         "key": "A",
         "value": {
             "name": "Variable A",
             "value": "aaa"
         }
     },
     "msg": "Variable A is named \"Variable A\" and has the value aaa"
}
ok: [MYHOST] => (item={'value': {u'name': u'Variable B', u'value': u'bbb'}, 'key': u'B'}) => {
     "item": {
         "key": "B",
         "value": {
             "name": "Variable B",
             "value": "bbb"
         }
     },
     "msg": "Variable B is named \"Variable B\" and has the value bbb"
}

PLAY RECAP *********************************************************************
MYHOST               : ok=2    changed=0    unreachable=0    failed=0

$


But this one fails:

----- testmyvars_2.yml -----------
---
- hosts: '{{ target }}'
   gather_facts: no
   tasks:
    - include_vars: file="./myvars_1.yml"

    - name: "Test myvars.yml"
debug: msg='Variable {{ item.key }} is named "{{ item.value.name }}" and has the value {{item.value.value}}'
      with_dict: "{{ var }}"
----------------------------------


$ ansible-playbook -vvv testmyvars_2.yml        \
                    --extra-vars "target=MYHOST" \
                    --ask-pass
Using /root/ansible-config/ansible.cfg as config file
SSH password:

PLAYBOOK: testmyvars_2.yml *****************************************************
1 plays in testmyvars_2.yml

PLAY [MYHOST] ************************************************************

TASK [include_vars] ************************************************************
task path: /root/ansible-config/testmyvars_2.yml:5
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/root/ansible/ansible/lib/ansible/executor/task_executor.py", line 124, in run
     res = self._execute()
File "/root/ansible/ansible/lib/ansible/executor/task_executor.py", line 447, in _execute
     result = self._handler.run(task_vars=variables)
File "/root/ansible/ansible/lib/ansible/plugins/action/include_vars.py", line 41, in run source = self._loader.path_dwim_relative(self._loader.get_basedir(), 'vars', source) File "/root/ansible/ansible/lib/ansible/parsing/dataloader.py", line 236, in path_dwim_relative
     if source.startswith('~') or source.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

fatal: [MYHOST]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

NO MORE HOSTS LEFT *************************************************************
         to retry, use: --limit @testmyvars_2.retry

PLAY RECAP *********************************************************************
MYHOST               : ok=0    changed=0    unreachable=0    failed=1

$

I also tried to use the absolute path to myvars_1.yml to no avail.

I could of course use the free-form of include_vars, but I'd like to eventually get rid of the top level variable in ./myvars_1.yml and use the "name" parameter to assign the included variables to a specific name.

Ansible version: ansible-playbook 2.2.0 (devel 3afe50dfe2)
Platform: openSuSE 13.1

Is this my bug or ansible's?  If it's mine: Any idea how I can fix it?

Cheers
frank


--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ab6422d9-6541-8089-d23f-407795a8de9d%40drosera.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to