Merge "Bump the ansible to 2"

This commit is contained in:
Jenkins 2016-05-26 10:57:27 +00:00 committed by Gerrit Code Review
commit 6f5239ce40
6 changed files with 65 additions and 60 deletions

3
.gitignore vendored
View File

@ -43,5 +43,8 @@ dev/vagrant/storage/
# Files created by reno build # Files created by reno build
releasenotes/build releasenotes/build
# Files generated by Ansible
ansible/site.retry
# Others # Others
.DS_Store .DS_Store

View File

@ -18,81 +18,70 @@ from ConfigParser import ConfigParser
from cStringIO import StringIO from cStringIO import StringIO
import os import os
from ansible.runner.return_data import ReturnData from ansible.plugins.action import ActionBase
from ansible import utils
from ansible.utils import template
class ActionModule(object): class ActionModule(ActionBase):
TRANSFERS_FILES = True TRANSFERS_FILES = True
def __init__(self, runner): def read_config(self, source, config):
self.runner = runner
def read_config(self, source, inject, config):
# Only use config if present # Only use config if present
if os.access(source, os.R_OK): if os.access(source, os.R_OK):
# template the source data locally & get ready to transfer with open(source, 'r') as f:
resultant = template.template_from_file(self.runner.basedir, template_data = f.read()
source, inject) result = self._templar.template(template_data)
fakefile = StringIO(result)
# Read in new results and merge this with the existing config
fakefile = StringIO(resultant)
config.readfp(fakefile) config.readfp(fakefile)
fakefile.close() fakefile.close()
def run(self, conn, tmp, module_name, module_args, inject, def run(self, tmp=None, task_vars=None):
complex_args=None, **kwargs):
args = {}
if complex_args:
args.update(complex_args)
args.update(utils.parse_kv(module_args))
dest = args.get('dest') if task_vars is None:
extra_vars = args.get('vars') task_vars = dict()
sources = args.get('sources') result = super(ActionModule, self).run(tmp, task_vars)
if extra_vars: if not tmp:
# Extend 'inject' args used in templating tmp = self._make_tmp_path()
if isinstance(extra_vars, dict):
inject.update(extra_vars) sources = self._task.args.get('sources', None)
else: extra_vars = self._task.args.get('vars', list())
inject.update(utils.parse_kv(extra_vars))
# Catch the case where sources is a str()
if not isinstance(sources, list): if not isinstance(sources, list):
sources = [sources] sources = [sources]
temp_vars = task_vars.copy()
temp_vars.update(extra_vars)
config = ConfigParser() config = ConfigParser()
old_vars = self._templar._available_variables
self._templar.set_available_variables(temp_vars)
for source in sources: for source in sources:
# template the source string self.read_config(source, config)
source = template.template(self.runner.basedir, source, inject)
try:
self.read_config(source, inject, config)
except Exception as e:
return ReturnData(conn=conn, comm_ok=False,
result={'failed': True, 'msg': str(e)})
self._templar.set_available_variables(old_vars)
# Dump configparser to string via an emulated file # Dump configparser to string via an emulated file
fakefile = StringIO() fakefile = StringIO()
config.write(fakefile) config.write(fakefile)
# Template the file to fill out any variables
content = template.template(self.runner.basedir, fakefile.getvalue(), remote_path = self._connection._shell.join_path(tmp, 'src')
inject) xfered = self._transfer_data(remote_path, fakefile.getvalue())
fakefile.close() fakefile.close()
# Ship this content over to a new file for use with the copy module new_module_args = self._task.args.copy()
xfered = self.runner._transfer_str(conn, tmp, 'source', content) del new_module_args['vars']
del new_module_args['sources']
copy_module_args = dict( new_module_args.update(
src=xfered, dict(
dest=dest, src=xfered
original_basename=os.path.basename(source), )
follow=True,
) )
return self.runner._execute_module(conn, tmp, 'copy', '',
inject=inject, result.update(self._execute_module(module_name='copy',
complex_args=copy_module_args) module_args=new_module_args,
task_vars=task_vars,
tmp=tmp))
return result

View File

@ -683,7 +683,8 @@ def generate_module():
] ]
return AnsibleModule( return AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
required_together=required_together required_together=required_together,
bypass_checks=True
) )
@ -691,15 +692,21 @@ def generate_nested_module():
module = generate_module() module = generate_module()
# We unnest the common dict and the update it with the other options # We unnest the common dict and the update it with the other options
new_args = module.params.get('common_options') new_args = module.params.pop('common_options', dict())
new_args.update(module._load_params()[0])
module.params = new_args # NOTE(jeffrey4l): merge the environment
env = module.params.pop('environment', dict())
if env:
new_args['environment'].update(env)
for key, value in module.params.iteritems():
if key in new_args and value is None:
continue
new_args[key] = value
# Override ARGS to ensure new args are used # Override ARGS to ensure new args are used
global MODULE_ARGS
global MODULE_COMPLEX_ARGS global MODULE_COMPLEX_ARGS
MODULE_ARGS = '' MODULE_COMPLEX_ARGS = json.dumps(new_args)
MODULE_COMPLEX_ARGS = json.dumps(module.params)
# Reprocess the args now that the common dict has been unnested # Reprocess the args now that the common dict has been unnested
return generate_module() return generate_module()

View File

@ -14,6 +14,8 @@
( groups['mariadb'] | length ) == 1 or ( groups['mariadb'] | length ) == 1 or
( delegate_host == 'None' and inventory_hostname != groups['mariadb'][0] ) ( delegate_host == 'None' and inventory_hostname != groups['mariadb'][0] )
# TODO(jeffrey4l), remove the task check when the wair_for bug is fixed
# https://github.com/ansible/ansible-modules-core/issues/2788
- name: Waiting for MariaDB service to be ready - name: Waiting for MariaDB service to be ready
wait_for: wait_for:
host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}" host: "{{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['address'] }}"
@ -21,3 +23,7 @@
connect_timeout: 1 connect_timeout: 1
timeout: 60 timeout: 60
search_regex: "MariaDB" search_regex: "MariaDB"
register: check_mariadb_port
until: check_mariadb_port | success
retries: 10
delay: 6

View File

@ -167,7 +167,7 @@ function configure_operator {
exit 1 exit 1
fi fi
pip install --upgrade "ansible<2" python-openstackclient python-neutronclient tox pip install --upgrade "ansible>=2" python-openstackclient python-neutronclient tox
pip install ${KOLLA_PATH} pip install ${KOLLA_PATH}

View File

@ -98,7 +98,7 @@ function setup_ansible {
mkdir /tmp/kolla mkdir /tmp/kolla
# TODO(SamYaple): Move to virtualenv # TODO(SamYaple): Move to virtualenv
sudo -H pip install -U "ansible<2" "docker-py>=1.6.0" "python-openstackclient" "python-neutronclient" sudo -H pip install -U "ansible>=2" "docker-py>=1.6.0" "python-openstackclient" "python-neutronclient"
detect_distro detect_distro
setup_inventory setup_inventory