# Newbie Developer Question: how does TaskQueueManager work exactly please?

**URL:** <https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081>\
**Category:** Ansible Developer\
**Created:** [April 6, 2016, 10:28pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081 "2016-04-06T22:28:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yang\_X](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@Yang\_X](https://forum.ansible.com/u/Yang_X)\
**Post date:** [April 6, 2016, 10:28pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081/1 "2016-04-06T22:28:42Z")

</div>

Hi,

I am trying to retrofit the pre2.0 runner based script to use the new TaskQueueManager interface and I tried to tweak the example given in the ansible API documentation and it simply will NOT work.

I have ssh keyless login already enabled on a list of hosts and my script is to run a ssh command, namely “ls” on these remote hosts and returns but I failed the attempt at the following:

#! /usr/bin/python

import os

import sys

import time

from socket import inet\_aton

import jinja2

from tempfile import NamedTemporaryFile

from ansible.playbook import Playbook

from ansible import utils

from docopt import docopt

from collections import namedtuple

from ansible.parsing.dataloader import DataLoader

from ansible.vars import VariableManager

from ansible.inventory import Inventory

from ansible.playbook.play import Play

from ansible.executor.task\_queue\_manager import TaskQueueManager

import re

hosts\_list = “adobe1,adobe2,adobe3”

# create play with tasks

play\_source = dict(

name = ‘command’,

hosts = hosts\_list,

gather\_facts = ‘no’,

tasks = [

dict(action=dict(module=‘shell’, args=‘ls’), register=‘shell\_out’),

]

)

Options = namedtuple(‘Options’, [‘connection’, ‘module\_path’, ‘forks’, ‘become’, ‘become\_method’, ‘become\_user’, ‘check’, ‘remote\_user’])

#initialize needed objects

variable\_manager = VariableManager()

loader = DataLoader()

options = Options(connection=‘local’, module\_path=‘./’, forks=100, become=None, become\_method=‘ssh’, become\_user=‘root’, check=False, remote\_user=‘root’)

passwords = dict(vault\_pass=‘’)

inventory = Inventory(loader=loader, variable\_manager=variable\_manager, host\_list=hosts\_list)

variable\_manager.set\_inventory(inventory)

play = Play().load(play\_source, variable\_manager=variable\_manager, loader=loader)

# actually run it

tqm = None

try:

tqm = TaskQueueManager(

inventory=inventory,

variable\_manager=variable\_manager,

loader=loader,

options=options,

passwords=passwords,

stdout\_callback=‘default’,

)

result = tqm.run(play)

finally:

if tqm is not None:

tqm.cleanup()

sys.exit(0)

**It complained when executing:**

raceback (most recent call last):

File “./run\_test.py”, line 60, in

result = tqm.run(play)

File “/Library/Python/2.7/site-packages/ansible/executor/task\_queue\_manager.py”, line 206, in run

play\_context = PlayContext(new\_play, self.\_options, self.passwords, self.\_connection\_lockfile.fileno())

File “/Library/Python/2.7/site-packages/ansible/playbook/play\_context.py”, line 212, in **init**

self.set\_options(options)

File “/Library/Python/2.7/site-packages/ansible/playbook/play\_context.py”, line 259, in set\_options

self.private\_key\_file = options.private\_key\_file

AttributeError: ‘Options’ object has no attribute ‘private\_key\_file’

Can somebody please point me to the correct direction? This seems to be such a trivial task and yet I can’t tweak it into working.

Many thanks,

Yang

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 7, 2016, 3:00pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081/2 "2016-04-07T15:00:02Z")

</div>

You are using a bit older version of Ansible than what the sample script implements, in initial 2.0 many other options were needed to be passed in, this was fixed for 2.0.1.

You can upgrade ansible or look at the docs version history for the ‘full list’ for the previous versions.

---

<div class="post-metadata">

**Author:** ![Yang\_X](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@Yang\_X](https://forum.ansible.com/u/Yang_X)\
**Post date:** [April 8, 2016, 10:17pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081/3 "2016-04-08T22:17:42Z")

</div>

Hi,

Thanks for the reply.

Is there code snippet which shows how it’s done in the newer version please?  
As I said, all I need to do is to perform some remote ssh commands on bunch of hosts.

Many thanks,

Yang

---

<div class="post-metadata">

**Author:** ![Jonathan\_Davila](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jonathan\_Davila](https://forum.ansible.com/u/Jonathan_Davila)\
**Post date:** [April 15, 2016, 1:40pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081/4 "2016-04-15T13:40:56Z")

</div>

You really shouldn’t be running Ansible this way.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [April 15, 2016, 1:48pm UTC](https://forum.ansible.com/t/newbie-developer-question-how-does-taskqueuemanager-work-exactly-please/21081/5 "2016-04-15T13:48:22Z")

</div>

An example is documented here:

[http://docs.ansible.com/ansible/developing\_api.html#python-api-2-0](http://docs.ansible.com/ansible/developing_api.html#python-api-2-0)
