Using lookup plugin within include_vars to build file name

143 views
Skip to first unread message

Sam Sen

unread,
Jan 5, 2017, 3:43:58 PM1/5/17
to Ansible Project
Running Ansible 2.1.1

I want to dynamically build the variable name for a file I wish to load using "include_vars." it doesn't work using the lookup plugin but the lookup plugin itself does work when I use the "debug" method.


- name: load var file
  include_vars
: "
{{ lookup('ini','environment section=environment_info file=/etc/abc123.conf') }}.yml"

Error:


TASK
[sam : load var file] *****************************************************
task path
: /home/ssen/ansible_ops/roles/sam/tasks/main.yml:5
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 124, in run
    res
= self._execute()
 
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 448, in _execute
    result
= self._handler.run(task_vars=variables)
 
File "/usr/lib/python2.7/site-packages/ansible/plugins/action/include_vars.py", line 39, in run
    source
= self._loader.path_dwim_relative(self._task._role._role_path, 'vars', source)
 
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 236, in path_dwim_relative
   
if source.startswith('~') or source.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'


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








Johannes Kastl

unread,
Jan 6, 2017, 3:47:34 PM1/6/17
to ansible...@googlegroups.com
On 05.01.17 21:43 Sam Sen wrote:
> Running Ansible 2.1.1
>
> I want to dynamically build the variable name for a file I wish to
> load using "include_vars." it doesn't work using the lookup plugin
> but the lookup plugin itself does work when I use the "debug"
> method.

Can you workaround it by setting a variable to the result of your
lookup and then use this variable for the file name?

Johannes

signature.asc

Sam S

unread,
Jan 7, 2017, 1:27:39 PM1/7/17
to ansible...@googlegroups.com
Yes that's what I ended up doing. I'm not sure why I'm not able to use the lookup plugin within the line.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/LIobDktTId0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e9f1fb44-1013-bb94-a4ca-8245366c67b1%40ojkastl.de.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages