Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-navigator failed when first meta task is skipped #598

Closed
abikouo opened this issue Oct 19, 2021 · 1 comment · Fixed by #627
Closed

ansible-navigator failed when first meta task is skipped #598

abikouo opened this issue Oct 19, 2021 · 1 comment · Fixed by #627
Labels
bug Researched, reproducible, committed to fix good first issue Bugs ideal for the first time, good for newcomers contributors

Comments

@abikouo
Copy link

abikouo commented Oct 19, 2021

ISSUE TYPE
  • Bug Report
SUMMARY
ANSIBLE-NAVIGATOR VERSION
ansible-navigator 1.1.0a1
CONFIGURATION
STEPS TO REPRODUCE
ansible-navigator run ./test_inventory.yml -m stdout  -v -i ./inventory.ini

test_inventory.yml

- hosts: all
  gather_facts: no
  
  tasks:
    - name: End play if remote host
      meta: end_host
      when: host_type != "container"

inventory.ini

[all]
localhost              ansible_connection=local   host_type="container"
EXPECTED RESULTS

navigator should execute the playbook successfully

ACTUAL RESULTS

ansible-navigator fails to execute playbook

TASK [End play if remote host] *************************************************
skipping: [localhost] => {"msg": "end_host conditional evaluated to false, continuing execution for localhost", "skip_reason": "end_host conditional evaluated to False, continuing execution for localhost"}
Traceback (most recent call last):
  File "/home/aubin/work/env/py38.0/bin/ansible-navigator", line 8, in <module>
    sys.exit(main())
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/cli.py", line 141, in main
    return_code = run(args)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/cli.py", line 79, in run
    return_code = run_action_stdout(args.app.replace("-", "_"), args)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/_actions.py", line 109, in run_stdout
    return action_cls(args).run_stdout()
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 249, in run_stdout
    self._dequeue()
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 612, in _dequeue
    self._handle_message(message)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 664, in _handle_message
    task["__duration"] = human_time(seconds=round(task["duration"], 2))
TypeError: type NoneType doesn't define __round__ method
@abikouo abikouo added bug Researched, reproducible, committed to fix new New issues and PRs to triaged labels Oct 19, 2021
@cidrblock
Copy link
Collaborator

hello @abikouo

thanks for the recreate here, I get the same result, it seems the entry for the task has a duration of None when we get it

0.0s _handle_message: 
      task={'__changed': False, '__result': 'SKIPPED', 'duration': None, 'end': None, 'event_loop': None, 'host': 'localhost', 'play': 'all', 'play_pattern': 'all', 'play_uuid': 'fa235c58-3d26-fd0c-f7ed-000000000006', 'playbook': '/home/bthornto/github/ansible-navigator/site.yaml', ...}

Which can't be rounded :)

This should be an easy fix, something like this in action/run/handle_message should work:

 if isinstance(task["duration"], (int, float)):
                        task["__duration"] = human_time(seconds=round(task["duration"], 2))
                    else:
                        msg = f"Task duration for \'{task['task']}\' was type {type(task['duration'])}, set to 0"
                        self._logger.debug(msg)
                        task["__duration"] = 0

which would result in a log message of

211029115352.446 DEBUG 'ansible_navigator.actions.run_playbook._handle_message' Task duration for 'End play if remote host' was type <class 'NoneType'>, set to 0

thanks again for this & the repro!

-Brad

@cidrblock cidrblock added the good first issue Bugs ideal for the first time, good for newcomers contributors label Oct 29, 2021
@relrod relrod removed the new New issues and PRs to triaged label Nov 1, 2021
ansible-zuul bot pushed a commit that referenced this issue Nov 24, 2021
set task duration to zero if None (fixes #598)

fixes #598 with @cidrblock 's recommendation
Worked with @alisonlhart was able to reproduce the issue and tested with steps listed in the issue.
before
Traceback (most recent call last):
  File "/home/aubin/work/env/py38.0/bin/ansible-navigator", line 8, in <module>
    sys.exit(main())
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/cli.py", line 141, in main
    return_code = run(args)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/cli.py", line 79, in run
    return_code = run_action_stdout(args.app.replace("-", "_"), args)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/_actions.py", line 109, in run_stdout
    return action_cls(args).run_stdout()
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 249, in run_stdout
    self._dequeue()
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 612, in _dequeue
    self._handle_message(message)
  File "/home/aubin/work/env/py38.0/lib/python3.8/site-packages/ansible_navigator/actions/run.py", line 664, in _handle_message
    task["__duration"] = human_time(seconds=round(task["duration"], 2))
TypeError: type NoneType doesn't define __round__ method

after
ansible-navigator run ./test_inventory.yml -m stdout  -v -i ./inventory.ini
No config file found; using defaults

PLAY [all] *********************************************************************

TASK [End play if remote host] *************************************************
skipping: [localhost] => {"msg": "end_host conditional evaluated to false, continuing execution for localhost", "skip_reason": "end_host conditional evaluated to False, continuing execution for localhost"}

PLAY RECAP *********************************************************************

ansible-navigator log entry
211123164144.219 DEBUG 'ansible_navigator.actions.run_playbook._handle_message' Task duration for 'End play if remote host' was type <class 'NoneType'>, set to 0

Reviewed-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
Reviewed-by: Bradley A. Thornton <bthornto@redhat.com>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Researched, reproducible, committed to fix good first issue Bugs ideal for the first time, good for newcomers contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants