run_once bug in 1.7.2

Hi List,

We still have some issues with this bug: https://github.com/ansible/ansible/issues/7432

The error message itself:

TASK: [fd4_config | backup database] ****************************************** 
skipping: [ISUFD4ACCIMP01 -> {{ fd4_config_database }}]
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 4, in <module>
    __import__('pkg_resources').run_script('ansible==1.7.2', 'ansible-playbook')
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 534, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1438, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/EGG-INFO/scripts/ansible-playbook", line 309, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/EGG-INFO/scripts/ansible-playbook", line 249, in main
    pb.run()
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/ansible/playbook/__init__.py", line 339, in run
    if not self._run_play(play):
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/ansible/playbook/__init__.py", line 695, in _run_play
    if not self._run_task(play, task, False):
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/ansible/playbook/__init__.py", line 471, in _run_task
    results = self._run_task_internal(task)
  File "/usr/lib/python2.6/site-packages/ansible-1.7.2-py2.6.egg/ansible/playbook/__init__.py", line 435, in _run_task_internal
    self.runner_callbacks.on_async_ok(host, res, poller.runner.vars_cache[host]['ansible_job_id'])
KeyError: 'ansible_job_id'

And this is the command beeing run:

- name: backup database
  shell: /usr/bin/mylvmbackup --vgname={{ fd4_config_vgname }} --lvname={{ fd4_config_lvname }} --backupdir=/tmp/mysql-backup --quiet --backuptype=tar &
  async: 90000
  poll: 0
  when: fd4_config_do_db_backup is defined
  run_once: true
  delegate_to: "{{ fd4_config_database }}"
  tags:
    - alert_web
    - importer_web
    - admin_web
    - root_web
    - war

It runs well on the first try, but on the second “visit” the run_once simply crashes.

Ansible version: 1.7.2

I’m trying to see if there’s a workaround, in the meantime: should I re-open the ticket?

Thanks,
Mark Maas

This fix was applied to the development branch (1.8), not 1.7.1,and did not happen to appear in the 1.7.2 dot release.

So you could use the development branch, otherwise it’s not fixed on 1.7.1

Ah ok, excellent.

For the record (Help to someone else)

I made a task that uses run_once and notifies a handler that would do the asynchronous poll thing.
And then I do: - meta: flush_handlers to get it to run then and there.