summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--INFO.yaml44
-rw-r--r--examples/launch.py4
-rw-r--r--requirements.txt4
-rw-r--r--setup.cfg4
-rw-r--r--snaps/openstack/create_instance.py7
-rw-r--r--snaps/openstack/utils/launch_utils.py16
-rw-r--r--snaps/playbook_runner.py3
-rw-r--r--snaps/provisioning/ansible_utils.py78
-rw-r--r--snaps/provisioning/tests/ansible_utils_tests.py6
9 files changed, 119 insertions, 47 deletions
diff --git a/INFO.yaml b/INFO.yaml
new file mode 100644
index 0000000..b29addf
--- /dev/null
+++ b/INFO.yaml
@@ -0,0 +1,44 @@
+---
+project: 'SNAPS-OO'
+project_creation_date: '07.02.2017'
+project_category: ''
+lifecycle_state: 'Incubation'
+project_lead: &opnfv_snaps_ptl
+ name: 'Steven Pisarski'
+ email: 's.pisarski@cablelabs.com'
+ id: 'spisarski'
+ company: 'cablelabs.com'
+ timezone: 'Unknown'
+primary_contact: *opnfv_snaps_ptl
+issue_tracking:
+ type: 'jira'
+ url: 'https://jira.opnfv.org/projects/SNAPS'
+ key: 'SNAPS'
+mailing_list:
+ type: 'mailman2'
+ url: 'opnfv-tech-discuss@lists.opnfv.org'
+ tag: '[snaps]'
+realtime_discussion:
+ type: irc
+ server: 'freenode.net'
+ channel: '#opnfv-snaps'
+meetings:
+ - type: 'gotomeeting+irc'
+ agenda: # eg: 'https://wiki.opnfv.org/display/'
+ url: # eg: 'https://global.gotomeeting.com/join/819733085'
+ server: 'freenode.net'
+ channel: '#opnfv-meeting'
+ repeats: 'weekly'
+ time: # eg: '16:00 UTC'
+repositories:
+ - 'snaps'
+committers:
+ - <<: *opnfv_snaps_ptl
+ - name: 'Randy Levensalor'
+ email: 'r.levensalor@cablelabs.com'
+ company: 'cablelabs.com'
+ id: 'RandyL'
+tsc:
+ # yamllint disable rule:line-length
+ approval: 'http//meetbot.opnfv.org/meetings/opnfv-meeting/2017/opnfv-meeting.2017-02-07-15.00.html'
+ # yamllint enable rule:line-length
diff --git a/examples/launch.py b/examples/launch.py
index 04bc5d6..cfd7f65 100644
--- a/examples/launch.py
+++ b/examples/launch.py
@@ -32,6 +32,10 @@ logger = logging.getLogger('snaps_launcher')
ARG_NOT_SET = "argument not set"
+from warnings import warn
+warn('This script will be removed in a subsequent release',
+ DeprecationWarning)
+
def main(arguments):
"""
diff --git a/requirements.txt b/requirements.txt
index 160d591..2404837 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,8 +8,10 @@ python-glanceclient>=2.8.0 # Apache-2.0
python-heatclient>=1.10.0 # Apache-2.0
python-cinderclient>=3.3.0 # Apache-2.0
python-magnumclient>=2.1.0,<2.3 # Apache-2.0
-ansible<2.4,>=2.1.0
+ansible>=2.4
wrapt>=1.7.0 # BSD License
scp
cryptography>=2.1 # BSD/Apache-2.0
concurrencytest
+jinja2
+keystoneauth1
diff --git a/setup.cfg b/setup.cfg
index c999c81..3d42cd7 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
-name = snaps
-version = 1.0
+name = snaps-oo
+version = 7.0.0
home-page = https://gerrit.opnfv.org/gerrit/gitweb?p=snaps.git;a=summary
author = Steve Pisarski
author-email = s.pisarski@cablelabs.com
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index 16bd0ce..b158a25 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -474,9 +474,12 @@ class OpenStackVmInstance(OpenStackComputeObject):
playbook
:param fip_name: the name of the floating IP to use for applying the
playbook (default - will take the first)
- :return: the return value from ansible
"""
- return ansible_utils.apply_playbook(
+ from warnings import warn
+ warn('This method will be removed in a subsequent release',
+ DeprecationWarning)
+
+ ansible_utils.apply_playbook(
pb_file_loc, [self.get_floating_ip(fip_name=fip_name).ip],
self.get_image_user(),
ssh_priv_key_file_path=self.keypair_settings.private_filepath,
diff --git a/snaps/openstack/utils/launch_utils.py b/snaps/openstack/utils/launch_utils.py
index 00ea822..ddaad12 100644
--- a/snaps/openstack/utils/launch_utils.py
+++ b/snaps/openstack/utils/launch_utils.py
@@ -53,6 +53,10 @@ from snaps.openstack.utils import deploy_utils, neutron_utils, keystone_utils
from snaps.openstack.utils.nova_utils import RebootType
from snaps.provisioning import ansible_utils
+from warnings import warn
+warn('This utility will be removed in a subsequent release',
+ DeprecationWarning)
+
logger = logging.getLogger('lanuch_utils')
DEFAULT_CREDS_KEY = 'admin'
@@ -464,17 +468,13 @@ def __apply_ansible_playbook(ansible_config, os_creds_dict, vm_dict,
ansible_config.get('variables'), os_creds_dict, vm_dict,
image_dict, flavor_dict, networks_dict, routers_dict)
- retval = ansible_utils.apply_playbook(
+ ansible_utils.apply_playbook(
ansible_config['playbook_location'], floating_ips, remote_user,
ssh_priv_key_file_path=private_key_filepath,
variables=variables,
proxy_setting=proxy_settings)
- if retval != 0:
- # Not a fatal type of event
- raise Exception(
- 'Error applying playbook found at location - %s',
- ansible_config.get('playbook_location'))
- elif ansible_config.get('post_processing'):
+
+ if 'post_processing' in ansible_config:
post_proc_config = ansible_config['post_processing']
if 'sleep' in post_proc_config:
time.sleep(post_proc_config['sleep'])
@@ -484,8 +484,6 @@ def __apply_ansible_playbook(ansible_config, os_creds_dict, vm_dict,
logger.info('Rebooting VM - %s', vm_name)
vm_dict[vm_name].reboot(RebootType.hard)
- return retval
-
def __get_connection_info(ansible_config, vm_dict):
"""
diff --git a/snaps/playbook_runner.py b/snaps/playbook_runner.py
index 03b7006..7b10390 100644
--- a/snaps/playbook_runner.py
+++ b/snaps/playbook_runner.py
@@ -67,12 +67,11 @@ def main(parsed_args):
if not variables.get('env_file'):
variables['env_file'] = parsed_args.env_file
- retval = ansible_utils.apply_playbook(
+ ansible_utils.apply_playbook(
parsed_args.playbook, [parsed_args.ip_addr], parsed_args.host_user,
ssh_priv_key_file_path=parsed_args.priv_key,
password=parsed_args.password, variables=variables,
proxy_setting=proxy_settings)
- exit(retval)
if __name__ == '__main__':
diff --git a/snaps/provisioning/ansible_utils.py b/snaps/provisioning/ansible_utils.py
index 83fe449..019a8e7 100644
--- a/snaps/provisioning/ansible_utils.py
+++ b/snaps/provisioning/ansible_utils.py
@@ -21,49 +21,58 @@ import paramiko
try:
from ansible.parsing.dataloader import DataLoader
- from ansible.vars import VariableManager
- from ansible.inventory import Inventory
+ from ansible.vars.manager import VariableManager
+ from ansible.inventory.manager import InventoryManager
from ansible.executor.playbook_executor import PlaybookExecutor
except:
pass
__author__ = 'spisarski'
+from warnings import warn
+warn('This utility will be removed in a subsequent release',
+ DeprecationWarning)
+
logger = logging.getLogger('ansible_utils')
-def apply_playbook(playbook_path, hosts_inv, host_user,
+def apply_playbook(playbook_path, hosts_inv=None, host_user=None,
ssh_priv_key_file_path=None, password=None, variables=None,
proxy_setting=None):
"""
Executes an Ansible playbook to the given host
:param playbook_path: the (relative) path to the Ansible playbook
:param hosts_inv: a list of hostnames/ip addresses to which to apply the
- Ansible playbook
+ Ansible playbook (not required when PB is configured for
+ localhost)
:param host_user: A user for the host instances (must be a password-less
- sudo user if playbook has "sudo: yes"
+ sudo user if playbook has "sudo: yes") (not required when
+ PB is configured for localhost)
:param ssh_priv_key_file_path: the file location of the ssh key. Required
- if password is None
+ if password is None (not required when PB is
+ configured for localhost)
:param password: the file location of the ssh key. Required if
- ssh_priv_key_file_path is None
+ ssh_priv_key_file_path is None (not required when PB is
+ configured for localhost)
:param variables: a dictionary containing any substitution variables needed
by the Jinga 2 templates
:param proxy_setting: instance of os_credentials.ProxySettings class
- :return: the results
+ :raises AnsibleException when the return code from the Ansible library is
+ not 0
+ :return: the return code from the Ansible library only when 0.
+ Implementation now raises an exception otherwise
"""
if not os.path.isfile(playbook_path):
- raise AnsibleException('Requested playbook not found - ' + playbook_path)
+ raise AnsibleException(
+ 'Requested playbook not found - ' + playbook_path)
pk_file_path = None
if ssh_priv_key_file_path:
pk_file_path = os.path.expanduser(ssh_priv_key_file_path)
if not password:
if not os.path.isfile(pk_file_path):
- raise AnsibleException('Requested private SSH key not found - ' +
- pk_file_path)
-
- if not ssh_priv_key_file_path and not password:
- raise AnsibleException('Invalid credentials, no priv key or password')
+ raise AnsibleException(
+ 'Requested private SSH key not found - ' + pk_file_path)
passwords = None
if password:
@@ -72,15 +81,20 @@ def apply_playbook(playbook_path, hosts_inv, host_user,
import ansible.constants
ansible.constants.HOST_KEY_CHECKING = False
- variable_manager = VariableManager()
+ loader = DataLoader()
+ inventory = InventoryManager(loader=loader)
+ if hosts_inv:
+ for host in hosts_inv:
+ inventory.add_host(host=host, group='ungrouped')
+ connection = 'ssh'
+ else:
+ connection = 'local'
+
+ variable_manager = VariableManager(loader=loader, inventory=inventory)
+
if variables:
variable_manager.extra_vars = variables
- loader = DataLoader()
- inventory = Inventory(loader=loader, variable_manager=variable_manager,
- host_list=hosts_inv)
- variable_manager.set_inventory(inventory)
-
ssh_extra_args = None
if proxy_setting and proxy_setting.ssh_proxy_cmd:
ssh_extra_args = '-o ProxyCommand=\'%s\'' % proxy_setting.ssh_proxy_cmd
@@ -90,14 +104,15 @@ def apply_playbook(playbook_path, hosts_inv, host_user,
'connection', 'module_path', 'forks', 'remote_user',
'private_key_file', 'ssh_common_args', 'ssh_extra_args',
'become', 'become_method', 'become_user', 'verbosity',
- 'check', 'timeout'])
+ 'check', 'timeout', 'diff'])
ansible_opts = options(
listtags=False, listtasks=False, listhosts=False, syntax=False,
- connection='ssh', module_path=None, forks=100, remote_user=host_user,
- private_key_file=pk_file_path, ssh_common_args=None,
- ssh_extra_args=ssh_extra_args, become=None, become_method=None,
- become_user=None, verbosity=11111, check=False, timeout=30)
+ connection=connection, module_path=None, forks=100,
+ remote_user=host_user, private_key_file=pk_file_path,
+ ssh_common_args=None, ssh_extra_args=ssh_extra_args, become=None,
+ become_method=None, become_user=None, verbosity=11111, check=False,
+ timeout=30, diff=None)
logger.debug('Setting up Ansible Playbook Executor for playbook - ' +
playbook_path)
@@ -110,7 +125,15 @@ def apply_playbook(playbook_path, hosts_inv, host_user,
passwords=passwords)
logger.debug('Executing Ansible Playbook - ' + playbook_path)
- return executor.run()
+ ret_val = executor.run()
+
+ if ret_val != 0:
+ raise AnsibleException(
+ 'Error applying playbook [{}] with value [{}] using the connection'
+ ' type of [{}]'.format(
+ playbook_path, ret_val, connection))
+
+ return ret_val
def ssh_client(ip, user, private_key_filepath=None, password=None,
@@ -143,9 +166,10 @@ def ssh_client(ip, user, private_key_filepath=None, password=None,
ssh.connect(
ip, username=user, key_filename=pk_abs_path, password=password,
sock=proxy_cmd)
+ logger.info('Obtained SSH connection to %s', ip)
return ssh
except Exception as e:
- logger.warning('Unable to connect via SSH with message - ' + str(e))
+ logger.debug('Unable to connect via SSH with message - ' + str(e))
class AnsibleException(Exception):
diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py
index 209b1e0..33e8edd 100644
--- a/snaps/provisioning/tests/ansible_utils_tests.py
+++ b/snaps/provisioning/tests/ansible_utils_tests.py
@@ -265,8 +265,7 @@ class AnsibleProvisioningTests(OSIntegrationTestCase):
relative_pb_path = pkg_resources.resource_filename(
'snaps.provisioning.tests.playbooks', 'simple_playbook.yml')
- retval = self.inst_creator.apply_ansible_playbook(relative_pb_path)
- self.assertEqual(0, retval)
+ self.inst_creator.apply_ansible_playbook(relative_pb_path)
ssh = ansible_utils.ssh_client(
ip, user, private_key_filepath=priv_key,
@@ -332,9 +331,8 @@ class AnsibleProvisioningTests(OSIntegrationTestCase):
relative_pb_path = pkg_resources.resource_filename(
'snaps.provisioning.tests.playbooks',
'template_playbook.yml')
- retval = self.inst_creator.apply_ansible_playbook(
+ self.inst_creator.apply_ansible_playbook(
relative_pb_path, variables={'name': 'Foo'})
- self.assertEqual(0, retval)
ssh = ansible_utils.ssh_client(
ip, user, private_key_filepath=priv_key,