本文整理匯總了Python中ansible.__version__方法的典型用法代碼示例。如果您正苦於以下問題:Python ansible.__version__方法的具體用法?Python ansible.__version__怎麽用?Python ansible.__version__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ansible
的用法示例。
在下文中一共展示了ansible.__version__方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: configure_context_processors
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def configure_context_processors(app):
@app.context_processor
def ctx_add_nav_data():
"""
Returns standard data that will be available in every template view.
"""
try:
models.Playbook.query.one()
empty_database = False
except models.MultipleResultsFound:
empty_database = False
except models.NoResultFound:
empty_database = True
# Get python version info
major, minor, micro, release, serial = sys.version_info
return dict(ara_version=ara_release,
ansible_version=ansible_version,
python_version="{0}.{1}".format(major, minor),
empty_database=empty_database)
示例2: get_play_prereqs_2
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def get_play_prereqs_2(self, options):
loader = DataLoader()
if self.vault_pass:
loader.set_vault_password(self.vault_pass)
variable_manager = VariableManager()
variable_manager.extra_vars = self.extra_vars
variable_manager.options_vars = {'ansible_version': self.version_info(ansible_version)}
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=options.inventory)
variable_manager.set_inventory(inventory)
# let inventory know which playbooks are using so it can know the
# basedirs
inventory.set_playbook_basedir(os.path.dirname(self.playbook_file))
return loader, inventory, variable_manager
示例3: get_play_prereqs_2_4
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def get_play_prereqs_2_4(self, options):
loader = DataLoader()
if self.vault_pass:
loader.set_vault_secrets([('default', VaultSecret(_bytes=to_bytes(self.vault_pass)))])
# create the inventory, and filter it based on the subset specified (if any)
inventory = InventoryManager(loader=loader, sources=options.inventory)
# create the variable manager, which will be shared throughout
# the code, ensuring a consistent view of global variables
try:
# Ansible 2.8
variable_manager = VariableManager(loader=loader, inventory=inventory,
version_info=self.version_info(ansible_version))
variable_manager._extra_vars = self.extra_vars
except TypeError:
variable_manager = VariableManager(loader=loader, inventory=inventory)
variable_manager.extra_vars = self.extra_vars
variable_manager.options_vars = {'ansible_version': self.version_info(ansible_version)}
return loader, inventory, variable_manager
示例4: run
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def run(self):
cur_python_ver = "%d.%d" % (sys.version_info[0], sys.version_info[1])
if LooseVersion(cur_python_ver) < LooseVersion(PYTHON_REQUIRE):
print("Error: Python version " + cur_python_ver + " < " + PYTHON_REQUIRE)
return False
os.system("%s -m pip install ansible>=%s" % (sys.executable, ABSIBLE_REQUIRE))
os.system("%s -m pip install ansible-runner>=%s" % (sys.executable, ABSIBLER_REQUIRE))
os.system("%s -m pip install sanic>=%s" % (sys.executable, SANIC_REQUIRE))
try:
import ansible
import ansible_runner
except ImportError:
print("Error: I can NOT work without ansible-runner")
# path = os.path.dirname(ansible.__file__)
if LooseVersion(ansible.__version__) >= LooseVersion(ABSIBLE_REQUIRE) and \
LooseVersion(pkg_resources.require("ansible_runner")[0].version) >= LooseVersion(ABSIBLER_REQUIRE):
install.run(self)
self.init_config_file()
print("\033[1;37mAnsible-api v%s install complete.\033[0m" %
__version__)
else:
print("Error: ansible [%s] or ansible-runner [%s] version too low" %
(ansible_runner.__version__, pkg_resources.require("ansible_runner")[0].version))
示例5: _assert_supported_release
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def _assert_supported_release():
"""
Throw AnsibleError with a descriptive message in case of being loaded into
an unsupported Ansible release.
"""
v = ansible.__version__
if not isinstance(v, tuple):
v = tuple(distutils.version.LooseVersion(v).version)
if v[:2] < ANSIBLE_VERSION_MIN:
raise ansible.errors.AnsibleError(
OLD_VERSION_MSG % (v, ANSIBLE_VERSION_MIN)
)
if v[:2] > ANSIBLE_VERSION_MAX:
raise ansible.errors.AnsibleError(
NEW_VERSION_MSG % (ansible.__version__, ANSIBLE_VERSION_MAX)
)
示例6: wrap_action_loader__get
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def wrap_action_loader__get(name, *args, **kwargs):
"""
While the mitogen strategy is active, trap action_loader.get() calls,
augmenting any fetched class with ActionModuleMixin, which replaces various
helper methods inherited from ActionBase with implementations that avoid
the use of shell fragments wherever possible.
This is used instead of static subclassing as it generalizes to third party
action plugins outside the Ansible tree.
"""
get_kwargs = {'class_only': True}
if name in ('fetch',):
name = 'mitogen_' + name
if ansible.__version__ >= '2.8':
get_kwargs['collection_list'] = kwargs.pop('collection_list', None)
klass = ansible_mitogen.loaders.action_loader__get(name, **get_kwargs)
if klass:
bases = (ansible_mitogen.mixins.ActionModuleMixin, klass)
adorned_klass = type(str(name), bases, {})
if kwargs.get('class_only'):
return adorned_klass
return adorned_klass(*args, **kwargs)
示例7: _set_temp_file_args
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def _set_temp_file_args(self, module_args, wrap_async):
# Ansible>2.5 module_utils reuses the action's temporary directory if
# one exists. Older versions error if this key is present.
if ansible.__version__ > '2.5':
if wrap_async:
# Sharing is not possible with async tasks, as in that case,
# the directory must outlive the action plug-in.
module_args['_ansible_tmpdir'] = None
else:
module_args['_ansible_tmpdir'] = self._connection._shell.tmpdir
# If _ansible_tmpdir is unset, Ansible>2.6 module_utils will use
# _ansible_remote_tmp as the location to create the module's temporary
# directory. Older versions error if this key is present.
if ansible.__version__ > '2.6':
module_args['_ansible_remote_tmp'] = (
self._connection.get_good_temp_dir()
)
示例8: _setup_responder
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def _setup_responder(responder):
"""
Configure :class:`mitogen.master.ModuleResponder` to only permit
certain packages, and to generate custom responses for certain modules.
"""
responder.whitelist_prefix('ansible')
responder.whitelist_prefix('ansible_mitogen')
_setup_simplejson(responder)
# Ansible 2.3 is compatible with Python 2.4 targets, however
# ansible/__init__.py is not. Instead, executor/module_common.py writes
# out a 2.4-compatible namespace package for unknown reasons. So we
# copy it here.
responder.add_source_override(
fullname='ansible',
path=ansible.__file__,
source=(ANSIBLE_PKG_OVERRIDE % (
ansible.__version__,
ansible.__author__,
)).encode(),
is_pkg=True,
)
示例9: __init__
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def __init__(self, complete=True, path='playbook.yml',
options={'fake': 'yes'}):
self.ansible_version = ansible_version
self.complete = complete
self.options = options
self.path = path
# Callback specific parameter
self._file_name = path
示例10: model
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def model(self):
return m.Playbook(ansible_version=ansible_version,
complete=self.complete,
options=self.options,
path=self.path)
示例11: _ara_config
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def _ara_config(config, key, env_var, default=None, section='ara',
value_type=None):
"""
Wrapper around Ansible's get_config backward/forward compatibility
"""
if default is None:
try:
# We're using env_var as keys in the DEFAULTS dict
default = DEFAULTS.get(env_var)
except KeyError as e:
msg = 'There is no default value for {0}: {1}'.format(key, str(e))
raise KeyError(msg)
# >= 2.3.0.0 (NOTE: Ansible trunk versioning scheme has 3 digits, not 4)
if LooseVersion(ansible_version) >= LooseVersion('2.3.0'):
return get_config(config, section, key, env_var, default,
value_type=value_type)
# < 2.3.0.0 compatibility
if value_type is None:
return get_config(config, section, key, env_var, default)
args = {
'boolean': dict(boolean=True),
'integer': dict(integer=True),
'list': dict(islist=True),
'tmppath': dict(istmppath=True)
}
return get_config(config, section, key, env_var, default,
**args[value_type])
示例12: v2_playbook_on_start
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def v2_playbook_on_start(self, playbook):
path = os.path.abspath(playbook._file_name)
if self._options is not None:
options = self._options.__dict__.copy()
else:
options = {}
# Potentially sanitize some user-specified keys
for parameter in app.config['ARA_IGNORE_PARAMETERS']:
if parameter in options:
msg = "Parameter not saved by ARA due to configuration"
options[parameter] = msg
LOG.debug('starting playbook %s', path)
self.playbook = models.Playbook(
ansible_version=ansible_version,
path=path,
options=options
)
self.playbook.start()
db.session.add(self.playbook)
db.session.commit()
file_ = self.get_or_create_file(path)
file_.is_playbook = True
# We need to persist the playbook id so it can be used by the modules
data = {
'playbook': {
'id': self.playbook.id
}
}
tmpfile = os.path.join(app.config['ARA_TMP_DIR'], 'ara.json')
with open(tmpfile, 'w') as file:
file.write(jsonutils.dumps(data))
示例13: get_vault_editor
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def get_vault_editor(vault_password):
"""
Get the correct VaultEditor object in different Ansible versions
"""
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
# for Ansible version 2.4.0 or higher
vault_secrets = [('default', VaultSecret(_bytes=to_bytes(vault_password)))]
return VaultEditor(VaultLib(vault_secrets))
else:
# for Ansible version 2.3.2 or lower
return VaultEditor(vault_password)
示例14: get_play_prereqs
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def get_play_prereqs(self, options):
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
# for Ansible version 2.4.0 or higher
return self.get_play_prereqs_2_4(options)
else:
# for Ansible version 2.3.2 or lower
return self.get_play_prereqs_2(options)
示例15: _gen_options
# 需要導入模塊: import ansible [as 別名]
# 或者: from ansible import __version__ [as 別名]
def _gen_options(self):
if LooseVersion(ansible_version) >= LooseVersion("2.8.0"):
from ansible.module_utils.common.collections import ImmutableDict
from ansible import context
context.CLIARGS = ImmutableDict(connection='ssh',
module_path=None,
forks=self.threads,
become=False,
become_method='sudo',
become_user='root',
check=False,
diff=False,
inventory=self.inventory_file,
private_key_file=self.pk_file,
remote_user=self.user)
Options = namedtuple('Options',
['connection',
'module_path',
'forks',
'become',
'become_method',
'become_user',
'check',
'diff',
'inventory',
'private_key_file',
'remote_user'])
options = Options(connection='ssh',
module_path=None,
forks=self.threads,
become=False,
become_method='sudo',
become_user='root',
check=False,
diff=False,
inventory=self.inventory_file,
private_key_file=self.pk_file,
remote_user=self.user)
return options