Developing a vars_plugin

113 views
Skip to first unread message

Guy Matz

unread,
Sep 11, 2014, 11:27:04 AM9/11/14
to ansible...@googlegroups.com
Hi!  Anyone have any advice on developing a vars_plugin?  This may sound kinda screwy, but for a chef -> ansible transition I need to access data from a chef data_bag in an ansible play . . .  I'm able to get the chef data using pychef, but I'm having issues when trying to run the code within vars_plugin code:

import chef

def get_dbag_data():
    chef_api = chef.autoconfigure()
    dbag, dbag_item = 'dbag', 'dbag_item'
    bag = chef.DataBag(dbag)  # some debugging shows the problem is here on the second run. . !
    item = bag[dbag_item]
    return item.to_dict()

The code above works outside of ansible, but when run in ansible it seems to get run twice, and fails on the "bag = chef.DataBag(dbag)" line the second time around.

Any thoughts would be greatly appreciated!

Thanks!
Guy

Matt Martz

unread,
Sep 11, 2014, 11:41:11 AM9/11/14
to ansible...@googlegroups.com
Perhaps you could show your vars_plugin?  There is the potential that it could be run twice, depending on where you call that code from.

The 3 following methods are all run 1 time in ansible.inventory.Inventory:

plugin.get_group_vars
plugin.run
plugin.get_host_vars

Also, as a heads up, this is probably a better discussion for ansible-devel.

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CABnTgtWLOnLrA0jn45n8HtDave37UDo8PbHe2JV9iU6yd5Kqrw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
ma...@sivel.net
http://sivel.net/

Guy Matz

unread,
Sep 11, 2014, 12:12:33 PM9/11/14
to ansible...@googlegroups.com
migrated to ansible-devel . . .  thanks!

Reply all
Reply to author
Forward
0 new messages