Migrating to Ansible v2.0 API --> What is this Options namedtuple?

Hi all,

We’re currently upgrading our system to the new Ansible v2.x API and while I understand that the API is not officially supported, I’m trying to understand how to use the options named tuple that appears to be popping up everywhere. In v1.9, we had passed all of our configuration information to ansible using extra_vars (such as ansible_connection, as well as some other configuration parameters)… Did these options take the place of that?

Thanks,
Fran

They are complementary, the Options tuple is simulating ‘command line options’, which still get overridden by connection variables.

Thanks, Brian.

So right now I’m essentially following this guide: http://docs.ansible.com/ansible/developing_api.html

Since we have all of our configuration options being passed in as variables, I essentially do variable_manager.extra_args = our_extra_args … since I have that, I’m not sure why I need to create an Options tuple and pass it into the TaskQueueManager? Then it seems like I would need to do, for example: options.connect = out_extra_args[‘ansible_connection’]?

I feel like I’m missing something here.

Fran

The API wasn’t really designed to work outside of the context of the ansible CLI utilities (or at least that wasn’t a primary concern). As such, TaskQueueManager expects you to pass in something that works like an optparse options object.

The example uses a named tuple, as that is easiest. The items in that documentation for namedtuple are the minimum required to satisfy the API. Any settings outside of what is mentioned in that namedtuple can be passed via other means.

Since you have mentioned you use extra_vars to pass in things like connection, you would just need to mimic the defaults of the options in optparse for the ansible clis. extra_vars would then override it.

So something like:

options = Options(connection=‘ssh’, …)
extra_vars = dict(ansible_connection=winrm, …)

Hope that makes sense, basically you have to give an options that satisfies the API (What the code is expecting). If you override via extra_vars, then so be it, but you still need to supply, even if different, those options in the options namedtuple.

Thanks, guys! Got everything working! :smiley: