Skip to content

Commit

Permalink
Merge pull request #34 from kdelee/become_methods
Browse files Browse the repository at this point in the history
Listen to warning and do what ansible wants in 2.8
  • Loading branch information
jlaska authored Mar 11, 2019
2 parents 8fc546a + 7b72811 commit 0f7eea8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pytest_ansible/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import ansible.utils
import ansible.errors

try:
from ansible.plugins import become_loader
except ImportError:
become_loader = None

from pytest_ansible.logger import get_logger
from pytest_ansible.fixtures import (ansible_adhoc, ansible_module, ansible_facts, localhost)
from pytest_ansible.host_manager import get_host_manager
Expand All @@ -16,6 +21,14 @@
(ansible_adhoc, ansible_module, ansible_facts, localhost)


def become_methods():
"""Return string list of become methods available to ansible."""
if become_loader:
return [method.name for method in become_loader.all()]
else:
return ansible.constants.BECOME_METHODS


def pytest_addoption(parser):
"""Add options to control ansible."""
log.debug("pytest_addoption() called")
Expand Down Expand Up @@ -71,7 +84,7 @@ def pytest_addoption(parser):
dest='ansible_become_method',
default=ansible.constants.DEFAULT_BECOME_METHOD,
help="privilege escalation method to use (default: %%(default)s), valid choices: [ %s ]" %
(' | '.join(ansible.constants.BECOME_METHODS)))
(' | '.join(become_methods())))
group.addoption('--become-user', '--ansible-become-user',
action='store',
dest='ansible_become_user',
Expand Down

0 comments on commit 0f7eea8

Please sign in to comment.