Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ dist: trusty
env:
- ANSIBLE_VERSION=2.4.0.0
- ANSIBLE_VERSION=2.3.0.0
- ANSIBLE_VERSION=2.2.0.0
- ANSIBLE_VERSION=2.1.3.0

install:
## Create Docker with Ansible modules and all dependancies
Expand Down
53 changes: 6 additions & 47 deletions library/juniper_junos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,57 +303,16 @@
import sys


def import_juniper_junos_common():
"""Imports the juniper_junos_common module from _module_utils_path.
"""From Ansible 2.1, Ansible uses Ansiballz framework for assembling modules
But custom module_utils directory is supported from Ansible 2.3
Reference for the issue: https://groups.google.com/forum/#!topic/ansible-project/J8FL7Z1J1Mw """

Ansible versions < 2.4 do not provide a way to package common code in a
role. This function solves that problem for juniper_junos_* modules by
reading the module arguments passed on stdin and interpreting the special
option _module_utils_path as a path to the the directory where the
juniper_junos_common module resides. It temporarily inserts this path at
the head of sys.path, imports the juniper_junos_common module, and removes
the path from sys.path. It then returns the imported juniper_junos_common
module object. All juniper_junos_* modules must include this boilerplate
function in order to import the shared juniper_junos_common module.
Args:
None.
Returns:
The juniper_junos_common module object.
Raises:
ImportError: If the juniper_junos_common object can not be imported
from the path specified by the module_utils_path argument.
"""
from ansible.module_utils.basic import AnsibleModule
import sys

juniper_junos_common = None
module = AnsibleModule(
argument_spec={
'_module_utils_path': dict(type='path', default=None),
# Avoids a warning about not specifying no_log for passwd.
'passwd': dict(no_log=True)
},
# Doesn't really work due to Ansible bug. Keeping it here for when
# Ansible bug is fixed.
no_log=True,
check_invalid_arguments=False,
bypass_checks=True
)
import_path = module.params.get('_module_utils_path')
if import_path is not None:
sys.path.insert(0, import_path)
import juniper_junos_common
del sys.path[0]
return juniper_junos_common
# Ansiballz packages module_utils into ansible.module_utils
from ansible.module_utils.basic import AnsibleModule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this import is necessary? It doesn't appear to be used.

from ansible.module_utils import juniper_junos_common


def main():
# Import juniper_junos_common
juniper_junos_common = import_juniper_junos_common()

# Create the module instance.
junos_module = juniper_junos_common.JuniperJunosModule(
argument_spec=dict(
Expand Down
53 changes: 6 additions & 47 deletions library/juniper_junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,57 +732,16 @@
import time


def import_juniper_junos_common():
"""Imports the juniper_junos_common module from _module_utils_path.
"""From Ansible 2.1, Ansible uses Ansiballz framework for assembling modules
But custom module_utils directory is supported from Ansible 2.3
Reference for the issue: https://groups.google.com/forum/#!topic/ansible-project/J8FL7Z1J1Mw """

Ansible versions < 2.4 do not provide a way to package common code in a
role. This function solves that problem for juniper_junos_* modules by
reading the module arguments passed on stdin and interpreting the special
option _module_utils_path as a path to the the directory where the
juniper_junos_common module resides. It temporarily inserts this path at
the head of sys.path, imports the juniper_junos_common module, and removes
the path from sys.path. It then returns the imported juniper_junos_common
module object. All juniper_junos_* modules must include this boilerplate
function in order to import the shared juniper_junos_common module.

Args:
None.

Returns:
The juniper_junos_common module object.

Raises:
ImportError: If the juniper_junos_common object can not be imported
from the path specified by the module_utils_path argument.
"""
from ansible.module_utils.basic import AnsibleModule
import sys

juniper_junos_common = None
module = AnsibleModule(
argument_spec={
'_module_utils_path': dict(type='path', default=None),
# Avoids a warning about not specifying no_log for passwd.
'passwd': dict(no_log=True)
},
# Doesn't really work due to Ansible bug. Keeping it here for when
# Ansible bug is fixed.
no_log=True,
check_invalid_arguments=False,
bypass_checks=True
)
import_path = module.params.get('_module_utils_path')
if import_path is not None:
sys.path.insert(0, import_path)
import juniper_junos_common
del sys.path[0]
return juniper_junos_common
# Ansiballz packages module_utils into ansible.module_utils
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils import juniper_junos_common


def main():
# Import juniper_junos_common
juniper_junos_common = import_juniper_junos_common()

# Choices which are defined in the common module.
config_format_choices = juniper_junos_common.CONFIG_FORMAT_CHOICES
config_database_choices = [None] + \
Expand Down
53 changes: 6 additions & 47 deletions library/juniper_junos_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,51 +171,13 @@



def import_juniper_junos_common():
"""Imports the juniper_junos_common module from _module_utils_path.

Ansible versions < 2.4 do not provide a way to package common code in a
role. This function solves that problem for juniper_junos_* modules by
reading the module arguments passed on stdin and interpreting the special
option _module_utils_path as a path to the the directory where the
juniper_junos_common module resides. It temporarily inserts this path at
the head of sys.path, imports the juniper_junos_common module, and removes
the path from sys.path. It then returns the imported juniper_junos_common
module object. All juniper_junos_* modules must include this boilerplate
function in order to import the shared juniper_junos_common module.
"""From Ansible 2.1, Ansible uses Ansiballz framework for assembling modules
But custom module_utils directory is supported from Ansible 2.3
Reference for the issue: https://groups.google.com/forum/#!topic/ansible-project/J8FL7Z1J1Mw """

Args:
None.

Returns:
The juniper_junos_common module object.

Raises:
ImportError: If the juniper_junos_common object can not be imported
from the path specified by the module_utils_path argument.
"""
from ansible.module_utils.basic import AnsibleModule
import sys

juniper_junos_common = None
module = AnsibleModule(
argument_spec={
'_module_utils_path': dict(type='path', default=None),
# Avoids a warning about not specifying no_log for passwd.
'passwd': dict(no_log=True)
},
# Doesn't really work due to Ansible bug. Keeping it here for when
# Ansible bug is fixed.
no_log=True,
check_invalid_arguments=False,
bypass_checks=True
)
import_path = module.params.get('_module_utils_path')
if import_path is not None:
sys.path.insert(0, import_path)
import juniper_junos_common
del sys.path[0]
return juniper_junos_common
# Ansiballz packages module_utils into ansible.module_utils
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils import juniper_junos_common


def get_facts_dict(junos_module):
Expand Down Expand Up @@ -318,9 +280,6 @@ def save_inventory(junos_module, inventory):


def main():
# Import juniper_junos_common
juniper_junos_common = import_juniper_junos_common()

config_format_choices = [None]
config_format_choices += juniper_junos_common.CONFIG_FORMAT_CHOICES

Expand Down
53 changes: 6 additions & 47 deletions library/juniper_junos_jsnapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,59 +203,18 @@
import os.path


def import_juniper_junos_common():
"""Imports the juniper_junos_common module from _module_utils_path.
"""From Ansible 2.1, Ansible uses Ansiballz framework for assembling modules
But custom module_utils directory is supported from Ansible 2.3
Reference for the issue: https://groups.google.com/forum/#!topic/ansible-project/J8FL7Z1J1Mw """

Ansible versions < 2.4 do not provide a way to package common code in a
role. This function solves that problem for juniper_junos_* modules by
reading the module arguments passed on stdin and interpreting the special
option _module_utils_path as a path to the the directory where the
juniper_junos_common module resides. It temporarily inserts this path at
the head of sys.path, imports the juniper_junos_common module, and removes
the path from sys.path. It then returns the imported juniper_junos_common
module object. All juniper_junos_* modules must include this boilerplate
function in order to import the shared juniper_junos_common module.

Args:
None.

Returns:
The juniper_junos_common module object.

Raises:
ImportError: If the juniper_junos_common object can not be imported
from the path specified by the module_utils_path argument.
"""
from ansible.module_utils.basic import AnsibleModule
import sys

juniper_junos_common = None
module = AnsibleModule(
argument_spec={
'_module_utils_path': dict(type='path', default=None),
# Avoids a warning about not specifying no_log for passwd.
'passwd': dict(no_log=True)
},
# Doesn't really work due to Ansible bug. Keeping it here for when
# Ansible bug is fixed.
no_log=True,
check_invalid_arguments=False,
bypass_checks=True
)
import_path = module.params.get('_module_utils_path')
if import_path is not None:
sys.path.insert(0, import_path)
import juniper_junos_common
del sys.path[0]
return juniper_junos_common
# Ansiballz packages module_utils into ansible.module_utils
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils import juniper_junos_common


def main():
JSNAPY_ACTION_CHOICES = ['check', 'snapcheck', 'snap_pre', 'snap_post']

# Import juniper_junos_common
juniper_junos_common = import_juniper_junos_common()

# Create the module instance.
junos_module = juniper_junos_common.JuniperJunosModule(
argument_spec=dict(
Expand Down
55 changes: 7 additions & 48 deletions library/juniper_junos_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,57 +380,16 @@
'''


def import_juniper_junos_common():
"""Imports the juniper_junos_common module from _module_utils_path.

Ansible versions < 2.4 do not provide a way to package common code in a
role. This function solves that problem for juniper_junos_* modules by
reading the module arguments passed on stdin and interpreting the special
option _module_utils_path as a path to the the directory where the
juniper_junos_common module resides. It temporarily inserts this path at
the head of sys.path, imports the juniper_junos_common module, and removes
the path from sys.path. It then returns the imported juniper_junos_common
module object. All juniper_junos_* modules must include this boilerplate
function in order to import the shared juniper_junos_common module.

Args:
None.

Returns:
The juniper_junos_common module object.

Raises:
ImportError: If the juniper_junos_common object can not be imported
from the path specified by the module_utils_path argument.
"""
from ansible.module_utils.basic import AnsibleModule
import sys

juniper_junos_common = None
module = AnsibleModule(
argument_spec={
'_module_utils_path': dict(type='path', default=None),
# Avoids a warning about not specifying no_log for passwd.
'passwd': dict(no_log=True)
},
# Doesn't really work due to Ansible bug. Keeping it here for when
# Ansible bug is fixed.
no_log=True,
check_invalid_arguments=False,
bypass_checks=True
)
import_path = module.params.get('_module_utils_path')
if import_path is not None:
sys.path.insert(0, import_path)
import juniper_junos_common
del sys.path[0]
return juniper_junos_common
"""From Ansible 2.1, Ansible uses Ansiballz framework for assembling modules
But custom module_utils directory is supported from Ansible 2.3
Reference for the issue: https://groups.google.com/forum/#!topic/ansible-project/J8FL7Z1J1Mw """

# Ansiballz packages module_utils into ansible.module_utils
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils import juniper_junos_common

def main():
# Import juniper_junos_common
juniper_junos_common = import_juniper_junos_common()

def main():
# The argument spec for the module.
argument_spec = dict(
dest=dict(type='str',
Expand Down
Loading